gnunet-solver-eval.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010-2013 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-tests/ats-testing-experiment.c
  18. * @brief ats benchmark: controlled experiment execution
  19. * @author Christian Grothoff
  20. * @author Matthias Wachs
  21. */
  22. #include "platform.h"
  23. #include "gnunet_util_lib.h"
  24. #include "gnunet_ats_plugin.h"
  25. #include "gnunet_ats_service.h"
  26. #include "ats-testing.h"
  27. /**
  28. * Experiments
  29. */
  30. const char *
  31. print_op (enum OperationType op)
  32. {
  33. switch (op)
  34. {
  35. case START_SEND:
  36. return "START_SEND";
  37. case STOP_SEND:
  38. return "STOP_SEND";
  39. case START_PREFERENCE:
  40. return "START_PREFERENCE";
  41. case STOP_PREFERENCE:
  42. return "STOP_PREFERENCE";
  43. default:
  44. break;
  45. }
  46. return "";
  47. }
  48. static struct Experiment *
  49. create_experiment ()
  50. {
  51. struct Experiment *e;
  52. e = GNUNET_new (struct Experiment);
  53. e->name = NULL;
  54. e->num_masters = 0;
  55. e->num_slaves = 0;
  56. e->start = NULL;
  57. e->total_duration = GNUNET_TIME_UNIT_ZERO;
  58. return e;
  59. }
  60. static void
  61. free_experiment (struct Experiment *e)
  62. {
  63. struct Episode *cur;
  64. struct Episode *next;
  65. struct GNUNET_ATS_TEST_Operation *cur_o;
  66. struct GNUNET_ATS_TEST_Operation *next_o;
  67. next = e->start;
  68. for (cur = next; NULL != cur; cur = next)
  69. {
  70. next = cur->next;
  71. next_o = cur->head;
  72. for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
  73. {
  74. next_o = cur_o->next;
  75. GNUNET_free (cur_o);
  76. }
  77. GNUNET_free (cur);
  78. }
  79. GNUNET_free (e->name);
  80. GNUNET_free (e->cfg_file);
  81. GNUNET_free (e);
  82. }
  83. static int
  84. load_episode (struct Experiment *e,
  85. struct Episode *cur,
  86. struct GNUNET_CONFIGURATION_Handle *cfg)
  87. {
  88. struct GNUNET_ATS_TEST_Operation *o;
  89. char *sec_name;
  90. char *op_name;
  91. char *op;
  92. char *type;
  93. char *pref;
  94. int op_counter = 0;
  95. fprintf (stderr, "Parsing episode %u\n", cur->id);
  96. GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
  97. while (1)
  98. {
  99. /* Load operation */
  100. GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
  101. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
  102. sec_name,
  103. op_name, &op))
  104. {
  105. GNUNET_free (op_name);
  106. break;
  107. }
  108. o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
  109. /* operations = set_rate, start_send, stop_send, set_preference */
  110. if (0 == strcmp (op, "start_send"))
  111. {
  112. o->type = START_SEND;
  113. }
  114. else if (0 == strcmp (op, "stop_send"))
  115. {
  116. o->type = STOP_SEND;
  117. }
  118. else if (0 == strcmp (op, "start_preference"))
  119. {
  120. o->type = START_PREFERENCE;
  121. }
  122. else if (0 == strcmp (op, "stop_preference"))
  123. {
  124. o->type = STOP_PREFERENCE;
  125. }
  126. else
  127. {
  128. fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
  129. op_counter, op, cur->id);
  130. GNUNET_free (op);
  131. GNUNET_free (op_name);
  132. GNUNET_free (sec_name);
  133. GNUNET_free (o);
  134. return GNUNET_SYSERR;
  135. }
  136. GNUNET_free (op_name);
  137. /* Get source */
  138. GNUNET_asprintf (&op_name, "op-%u-src", op_counter);
  139. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
  140. sec_name,
  141. op_name,
  142. &o->src_id))
  143. {
  144. fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
  145. op_counter, op, cur->id);
  146. GNUNET_free (op);
  147. GNUNET_free (op_name);
  148. GNUNET_free (sec_name);
  149. GNUNET_free (o);
  150. return GNUNET_SYSERR;
  151. }
  152. if (o->src_id > (e->num_masters - 1))
  153. {
  154. fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
  155. o->src_id, op_counter, op, cur->id);
  156. GNUNET_free (op);
  157. GNUNET_free (op_name);
  158. GNUNET_free (sec_name);
  159. GNUNET_free (o);
  160. return GNUNET_SYSERR;
  161. }
  162. GNUNET_free (op_name);
  163. /* Get destination */
  164. GNUNET_asprintf (&op_name, "op-%u-dest", op_counter);
  165. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
  166. sec_name,
  167. op_name,
  168. &o->dest_id))
  169. {
  170. fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
  171. op_counter, op, cur->id);
  172. GNUNET_free (op);
  173. GNUNET_free (op_name);
  174. GNUNET_free (sec_name);
  175. GNUNET_free (o);
  176. return GNUNET_SYSERR;
  177. }
  178. if (o->dest_id > (e->num_slaves - 1))
  179. {
  180. fprintf (stderr,
  181. "Invalid destination %llu in operation %u `%s' in episode %u\n",
  182. o->dest_id,
  183. op_counter,
  184. op,
  185. cur->id);
  186. GNUNET_free (op);
  187. GNUNET_free (op_name);
  188. GNUNET_free (sec_name);
  189. GNUNET_free (o);
  190. return GNUNET_SYSERR;
  191. }
  192. GNUNET_free (op_name);
  193. GNUNET_asprintf (&op_name, "op-%u-type", op_counter);
  194. if ((GNUNET_SYSERR !=
  195. GNUNET_CONFIGURATION_get_value_string (cfg,
  196. sec_name,
  197. op_name,
  198. &type)) &&
  199. (STOP_SEND != o->type) &&
  200. (STOP_PREFERENCE != o->type))
  201. {
  202. /* Load arguments for set_rate, start_send, set_preference */
  203. if (0 == strcmp (type, "constant"))
  204. {
  205. o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
  206. }
  207. else if (0 == strcmp (type, "linear"))
  208. {
  209. o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
  210. }
  211. else if (0 == strcmp (type, "sinus"))
  212. {
  213. o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
  214. }
  215. else if (0 == strcmp (type, "random"))
  216. {
  217. o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
  218. }
  219. else
  220. {
  221. fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
  222. op_counter, op, cur->id);
  223. GNUNET_free (type);
  224. GNUNET_free (op);
  225. GNUNET_free (op_name);
  226. GNUNET_free (sec_name);
  227. GNUNET_free (o);
  228. return GNUNET_SYSERR;
  229. }
  230. GNUNET_free (op_name);
  231. /* Get base rate */
  232. GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
  233. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
  234. sec_name,
  235. op_name,
  236. &o->base_rate))
  237. {
  238. fprintf (stderr,
  239. "Missing base rate in operation %u `%s' in episode %u\n",
  240. op_counter, op, cur->id);
  241. GNUNET_free (type);
  242. GNUNET_free (op);
  243. GNUNET_free (op_name);
  244. GNUNET_free (sec_name);
  245. GNUNET_free (o);
  246. return GNUNET_SYSERR;
  247. }
  248. GNUNET_free (op_name);
  249. /* Get max rate */
  250. GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
  251. if (GNUNET_SYSERR ==
  252. GNUNET_CONFIGURATION_get_value_number (cfg,
  253. sec_name,
  254. op_name,
  255. &o->max_rate))
  256. {
  257. if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
  258. (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
  259. (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
  260. {
  261. fprintf (stderr,
  262. "Missing max rate in operation %u `%s' in episode %u\n",
  263. op_counter, op, cur->id);
  264. GNUNET_free (type);
  265. GNUNET_free (op_name);
  266. GNUNET_free (op);
  267. GNUNET_free (sec_name);
  268. GNUNET_free (o);
  269. return GNUNET_SYSERR;
  270. }
  271. }
  272. GNUNET_free (op_name);
  273. /* Get period */
  274. GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
  275. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
  276. sec_name,
  277. op_name,
  278. &o->period))
  279. {
  280. o->period = cur->duration;
  281. }
  282. GNUNET_free (op_name);
  283. if (START_PREFERENCE == o->type)
  284. {
  285. /* Get frequency */
  286. GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
  287. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
  288. sec_name,
  289. op_name,
  290. &o->frequency))
  291. {
  292. fprintf (stderr,
  293. "Missing frequency in operation %u `%s' in episode %u\n",
  294. op_counter, op, cur->id);
  295. GNUNET_free (type);
  296. GNUNET_free (op_name);
  297. GNUNET_free (op);
  298. GNUNET_free (sec_name);
  299. GNUNET_free (o);
  300. return GNUNET_SYSERR;
  301. }
  302. GNUNET_free (op_name);
  303. /* Get preference */
  304. GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
  305. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
  306. sec_name,
  307. op_name,
  308. &pref))
  309. {
  310. fprintf (stderr,
  311. "Missing preference in operation %u `%s' in episode %u\n",
  312. op_counter, op, cur->id);
  313. GNUNET_free (type);
  314. GNUNET_free (op_name);
  315. GNUNET_free (op);
  316. GNUNET_free (sec_name);
  317. GNUNET_free (pref);
  318. GNUNET_free (o);
  319. return GNUNET_SYSERR;
  320. }
  321. if (0 == strcmp (pref, "bandwidth"))
  322. o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
  323. else if (0 == strcmp (pref, "latency"))
  324. o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
  325. else
  326. {
  327. fprintf (stderr,
  328. "Invalid preference in operation %u `%s' in episode %u\n",
  329. op_counter,
  330. op,
  331. cur->id);
  332. GNUNET_free (type);
  333. GNUNET_free (op_name);
  334. GNUNET_free (op);
  335. GNUNET_free (sec_name);
  336. GNUNET_free (pref);
  337. GNUNET_free (o);
  338. return GNUNET_SYSERR;
  339. }
  340. GNUNET_free (pref);
  341. GNUNET_free (op_name);
  342. }
  343. }
  344. /* Safety checks */
  345. if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
  346. (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
  347. {
  348. if ((o->max_rate - o->base_rate) > o->base_rate)
  349. {
  350. /* This will cause an underflow */
  351. GNUNET_break (0);
  352. }
  353. fprintf (stderr,
  354. "Selected max rate and base rate cannot be used for desired traffic form!\n");
  355. }
  356. if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
  357. fprintf (stderr,
  358. "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
  359. op_counter, cur->id, print_op (o->type), o->src_id,
  360. o->dest_id, (NULL != type) ? type : "",
  361. o->base_rate, o->max_rate,
  362. GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
  363. else
  364. fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
  365. op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
  366. GNUNET_free (type);
  367. GNUNET_free (op);
  368. GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o);
  369. op_counter++;
  370. }
  371. GNUNET_free (sec_name);
  372. return GNUNET_OK;
  373. }
  374. static int
  375. load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
  376. {
  377. int e_counter = 0;
  378. char *sec_name;
  379. struct GNUNET_TIME_Relative e_duration;
  380. struct Episode *cur;
  381. struct Episode *last;
  382. e_counter = 0;
  383. last = NULL;
  384. while (1)
  385. {
  386. GNUNET_asprintf (&sec_name, "episode-%u", e_counter);
  387. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
  388. sec_name,
  389. "duration",
  390. &e_duration))
  391. {
  392. GNUNET_free (sec_name);
  393. break;
  394. }
  395. cur = GNUNET_new (struct Episode);
  396. cur->duration = e_duration;
  397. cur->id = e_counter;
  398. if (GNUNET_OK != load_episode (e, cur, cfg))
  399. {
  400. GNUNET_free (sec_name);
  401. GNUNET_free (cur);
  402. return GNUNET_SYSERR;
  403. }
  404. fprintf (stderr, "Found episode %u with duration %s \n",
  405. e_counter,
  406. GNUNET_STRINGS_relative_time_to_string (cur->duration,
  407. GNUNET_YES));
  408. /* Update experiment */
  409. e->num_episodes++;
  410. e->total_duration = GNUNET_TIME_relative_add (e->total_duration,
  411. cur->duration);
  412. /* Put in linked list */
  413. if (NULL == last)
  414. e->start = cur;
  415. else
  416. last->next = cur;
  417. GNUNET_free (sec_name);
  418. e_counter++;
  419. last = cur;
  420. }
  421. return e_counter;
  422. }
  423. static void
  424. timeout_experiment (void *cls)
  425. {
  426. struct Experiment *e = cls;
  427. e->experiment_timeout_task = NULL;
  428. fprintf (stderr, "Experiment timeout!\n");
  429. if (NULL != e->episode_timeout_task)
  430. {
  431. GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
  432. e->episode_timeout_task = NULL;
  433. }
  434. e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
  435. GNUNET_SYSERR);
  436. }
  437. static void
  438. enforce_start_send (struct GNUNET_ATS_TEST_Operation *op)
  439. {
  440. /*
  441. struct BenchmarkPeer *peer;
  442. struct BenchmarkPartner *partner;
  443. peer = GNUNET_ATS_TEST_get_peer (op->src_id);
  444. if (NULL == peer)
  445. {
  446. GNUNET_break (0);
  447. return;
  448. }
  449. partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
  450. if (NULL == partner)
  451. {
  452. GNUNET_break (0);
  453. return;
  454. }
  455. fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
  456. if (NULL != partner->tg)
  457. {
  458. fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
  459. GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
  460. partner->tg = NULL;
  461. }
  462. partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
  463. op->tg_type, op->base_rate, op->max_rate, op->period,
  464. GNUNET_TIME_UNIT_FOREVER_REL);
  465. */}
  466. static void
  467. enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op)
  468. {
  469. /*
  470. struct BenchmarkPartner *p;
  471. p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
  472. if (NULL == p)
  473. {
  474. GNUNET_break (0);
  475. return;
  476. }
  477. fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
  478. if (NULL != p->tg)
  479. {
  480. fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
  481. op->src_id, op->dest_id);
  482. GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
  483. p->tg = NULL;
  484. }
  485. */}
  486. static void
  487. enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
  488. {
  489. /*
  490. struct BenchmarkPeer *peer;
  491. struct BenchmarkPartner *partner;
  492. peer = GNUNET_ATS_TEST_get_peer (op->src_id);
  493. if (NULL == peer)
  494. {
  495. GNUNET_break (0);
  496. return;
  497. }
  498. partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
  499. if (NULL == partner)
  500. {
  501. GNUNET_break (0);
  502. return;
  503. }
  504. fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
  505. if (NULL != partner->pg)
  506. {
  507. fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
  508. op->src_id, op->dest_id);
  509. GNUNET_ATS_TEST_generate_preferences_stop(partner->pg);
  510. partner->pg = NULL;
  511. }
  512. partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner,
  513. op->tg_type, op->base_rate, op->max_rate, op->period, op->frequency,
  514. op->pref_type);
  515. */}
  516. static void
  517. enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
  518. {
  519. /*
  520. struct BenchmarkPartner *p;
  521. p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
  522. if (NULL == p)
  523. {
  524. GNUNET_break (0);
  525. return;
  526. }
  527. fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
  528. if (NULL != p->pg)
  529. {
  530. fprintf (stderr, "Stopping preference between master %llu slave %llu\n",
  531. op->src_id, op->dest_id);
  532. GNUNET_ATS_TEST_generate_preferences_stop (p->pg);
  533. p->pg = NULL;
  534. }
  535. */}
  536. static void
  537. enforce_episode (struct Episode *ep)
  538. {
  539. struct GNUNET_ATS_TEST_Operation *cur;
  540. for (cur = ep->head; NULL != cur; cur = cur->next)
  541. {
  542. fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n",
  543. print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate);
  544. switch (cur->type)
  545. {
  546. case START_SEND:
  547. enforce_start_send (cur);
  548. break;
  549. case STOP_SEND:
  550. enforce_stop_send (cur);
  551. break;
  552. case START_PREFERENCE:
  553. enforce_start_preference (cur);
  554. break;
  555. case STOP_PREFERENCE:
  556. enforce_stop_preference (cur);
  557. break;
  558. default:
  559. break;
  560. }
  561. }
  562. }
  563. static void
  564. timeout_episode (void *cls)
  565. {
  566. struct Experiment *e = cls;
  567. e->episode_timeout_task = NULL;
  568. if (NULL != e->ep_done_cb)
  569. e->ep_done_cb (e->cur);
  570. /* Scheduling next */
  571. e->cur = e->cur->next;
  572. if (NULL == e->cur)
  573. {
  574. /* done */
  575. fprintf (stderr, "Last episode done!\n");
  576. if (NULL != e->experiment_timeout_task)
  577. {
  578. GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
  579. e->experiment_timeout_task = NULL;
  580. }
  581. e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
  582. GNUNET_OK);
  583. return;
  584. }
  585. fprintf (stderr, "Running episode %u with timeout %s\n",
  586. e->cur->id,
  587. GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
  588. GNUNET_YES));
  589. enforce_episode (e->cur);
  590. e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
  591. &timeout_episode, e);
  592. }
  593. void
  594. GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
  595. GNUNET_ATS_TESTING_EpisodeDoneCallback
  596. ep_done_cb,
  597. GNUNET_ATS_TESTING_ExperimentDoneCallback
  598. e_done_cb)
  599. {
  600. fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
  601. GNUNET_STRINGS_relative_time_to_string (e->max_duration,
  602. GNUNET_YES));
  603. e->e_done_cb = e_done_cb;
  604. e->ep_done_cb = ep_done_cb;
  605. e->start_time = GNUNET_TIME_absolute_get ();
  606. /* Start total time out */
  607. e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
  608. &timeout_experiment,
  609. e);
  610. /* Start */
  611. e->cur = e->start;
  612. fprintf (stderr, "Running episode %u with timeout %s\n",
  613. e->cur->id,
  614. GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
  615. GNUNET_YES));
  616. enforce_episode (e->cur);
  617. e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
  618. &timeout_episode, e);
  619. }
  620. struct Experiment *
  621. GNUNET_ATS_solvers_experimentation_load (char *filename)
  622. {
  623. struct Experiment *e;
  624. struct GNUNET_CONFIGURATION_Handle *cfg;
  625. e = NULL;
  626. cfg = GNUNET_CONFIGURATION_create ();
  627. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
  628. {
  629. fprintf (stderr, "Failed to load `%s'\n", filename);
  630. GNUNET_CONFIGURATION_destroy (cfg);
  631. return NULL;
  632. }
  633. e = create_experiment ();
  634. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
  635. "name", &e->name))
  636. {
  637. fprintf (stderr, "Invalid %s", "name");
  638. free_experiment (e);
  639. return NULL;
  640. }
  641. else
  642. fprintf (stderr, "Experiment name: `%s'\n", e->name);
  643. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
  644. "experiment",
  645. "cfg_file",
  646. &e->cfg_file))
  647. {
  648. fprintf (stderr, "Invalid %s", "cfg_file");
  649. free_experiment (e);
  650. return NULL;
  651. }
  652. else
  653. fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
  654. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
  655. "masters",
  656. &e->num_masters))
  657. {
  658. fprintf (stderr, "Invalid %s", "masters");
  659. free_experiment (e);
  660. return NULL;
  661. }
  662. else
  663. fprintf (stderr, "Experiment masters: `%llu'\n",
  664. e->num_masters);
  665. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment",
  666. "slaves",
  667. &e->num_slaves))
  668. {
  669. fprintf (stderr, "Invalid %s", "slaves");
  670. free_experiment (e);
  671. return NULL;
  672. }
  673. else
  674. fprintf (stderr, "Experiment slaves: `%llu'\n",
  675. e->num_slaves);
  676. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
  677. "log_freq",
  678. &e->log_freq))
  679. {
  680. fprintf (stderr, "Invalid %s", "log_freq");
  681. free_experiment (e);
  682. return NULL;
  683. }
  684. else
  685. fprintf (stderr, "Experiment logging frequency: `%s'\n",
  686. GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
  687. if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
  688. "max_duration",
  689. &e->max_duration))
  690. {
  691. fprintf (stderr, "Invalid %s", "max_duration");
  692. free_experiment (e);
  693. return NULL;
  694. }
  695. else
  696. fprintf (stderr, "Experiment duration: `%s'\n",
  697. GNUNET_STRINGS_relative_time_to_string (e->max_duration,
  698. GNUNET_YES));
  699. load_episodes (e, cfg);
  700. fprintf (stderr, "Loaded %u episodes with total duration %s\n",
  701. e->num_episodes,
  702. GNUNET_STRINGS_relative_time_to_string (e->total_duration,
  703. GNUNET_YES));
  704. GNUNET_CONFIGURATION_destroy (cfg);
  705. return e;
  706. }
  707. void
  708. GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
  709. {
  710. if (NULL != e->experiment_timeout_task)
  711. {
  712. GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
  713. e->experiment_timeout_task = NULL;
  714. }
  715. if (NULL != e->episode_timeout_task)
  716. {
  717. GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
  718. e->episode_timeout_task = NULL;
  719. }
  720. free_experiment (e);
  721. }
  722. /**
  723. * Solver
  724. */
  725. struct GNUNET_ATS_TESTING_SolverHandle
  726. {
  727. char *plugin;
  728. struct GNUNET_ATS_PluginEnvironment env;
  729. void *solver;
  730. };
  731. enum GNUNET_ATS_Solvers
  732. {
  733. GNUNET_ATS_SOLVER_PROPORTIONAL,
  734. GNUNET_ATS_SOLVER_MLP,
  735. GNUNET_ATS_SOLVER_RIL,
  736. };
  737. void
  738. GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh)
  739. {
  740. GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
  741. GNUNET_free (sh->plugin);
  742. GNUNET_free (sh);
  743. }
  744. struct GNUNET_ATS_TESTING_SolverHandle *
  745. GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
  746. {
  747. struct GNUNET_ATS_TESTING_SolverHandle *sh;
  748. char *solver_str;
  749. switch (type)
  750. {
  751. case GNUNET_ATS_SOLVER_PROPORTIONAL:
  752. solver_str = "proportional";
  753. break;
  754. case GNUNET_ATS_SOLVER_MLP:
  755. solver_str = "mlp";
  756. break;
  757. case GNUNET_ATS_SOLVER_RIL:
  758. solver_str = "ril";
  759. break;
  760. default:
  761. GNUNET_break (0);
  762. return NULL;
  763. break;
  764. }
  765. sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle);
  766. GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
  767. // sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
  768. if (NULL == sh->solver)
  769. {
  770. fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
  771. exit (1);
  772. }
  773. return sh;
  774. }
  775. static struct Experiment *e;
  776. static struct GNUNET_ATS_TESTING_SolverHandle *sh;
  777. /**
  778. * cmd option -e: experiment file
  779. */
  780. static char *opt_exp_file;
  781. static char *opt_solver;
  782. /**
  783. * cmd option -l: enable logging
  784. */
  785. static int opt_log;
  786. /**
  787. * cmd option -p: enable plots
  788. */
  789. static int opt_plot;
  790. /**
  791. * cmd option -v: verbose logs
  792. */
  793. static int opt_verbose;
  794. static void
  795. run (void *cls, char *const *args, const char *cfgfile,
  796. const struct GNUNET_CONFIGURATION_Handle *cfg)
  797. {
  798. enum GNUNET_ATS_Solvers solver;
  799. if (NULL == opt_exp_file)
  800. {
  801. fprintf (stderr, "No experiment given ...\n");
  802. exit (1);
  803. }
  804. if (NULL == opt_solver)
  805. {
  806. fprintf (stderr, "No solver given ...\n");
  807. exit (1);
  808. }
  809. if (0 == strcmp (opt_solver, "mlp"))
  810. {
  811. solver = GNUNET_ATS_SOLVER_MLP;
  812. }
  813. else if (0 == strcmp (opt_solver, "proportional"))
  814. {
  815. solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
  816. }
  817. else if (0 == strcmp (opt_solver, "ril"))
  818. {
  819. solver = GNUNET_ATS_SOLVER_RIL;
  820. }
  821. else
  822. {
  823. fprintf (stderr, "No solver given ...");
  824. return;
  825. }
  826. /* load experiment */
  827. e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
  828. if (NULL == e)
  829. {
  830. fprintf (stderr, "Failed to load experiment ...\n");
  831. return;
  832. }
  833. /* load solver */
  834. sh = GNUNET_ATS_solvers_solver_start (solver);
  835. if (NULL == sh)
  836. {
  837. fprintf (stderr, "Failed to start solver ...\n");
  838. return;
  839. }
  840. /* start logging */
  841. /* run experiment */
  842. /* WAIT */
  843. }
  844. /**
  845. * Main function of the benchmark
  846. *
  847. * @param argc argument count
  848. * @param argv argument values
  849. */
  850. int
  851. main (int argc, char *argv[])
  852. {
  853. opt_exp_file = NULL;
  854. opt_solver = NULL;
  855. opt_log = GNUNET_NO;
  856. opt_plot = GNUNET_NO;
  857. struct GNUNET_GETOPT_CommandLineOption options[] = {
  858. GNUNET_GETOPT_option_string ('s',
  859. "solver",
  860. NULL,
  861. gettext_noop ("solver to use"),
  862. &opt_solver),
  863. GNUNET_GETOPT_option_string ('e',
  864. "experiment",
  865. NULL,
  866. gettext_noop ("experiment to use"),
  867. &opt_exp_file),
  868. GNUNET_GETOPT_option_flag ('e',
  869. "experiment",
  870. gettext_noop ("experiment to use"),
  871. &opt_verbose),
  872. GNUNET_GETOPT_OPTION_END
  873. };
  874. if (GNUNET_OK !=
  875. GNUNET_PROGRAM_run (argc,
  876. argv, argv[0],
  877. NULL,
  878. options,
  879. &run, argv[0]))
  880. return 1;
  881. return 0;
  882. }
  883. /* end of file gnunet-solver-eval.c*/