gnunet-nse-profiler.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011, 2012 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 nse/gnunet-nse-profiler.c
  18. *
  19. * @brief Profiling driver for the network size estimation service.
  20. * Generally, the profiler starts a given number of peers,
  21. * then churns some off, waits a certain amount of time, then
  22. * churns again, and repeats.
  23. * @author Christian Grothoff
  24. * @author Nathan Evans
  25. * @author Sree Harsha Totakura
  26. */
  27. #include "platform.h"
  28. #include "gnunet_testbed_service.h"
  29. #include "gnunet_nse_service.h"
  30. /**
  31. * Generic loggins shorthand
  32. */
  33. #define LOG(kind,...) \
  34. GNUNET_log (kind, __VA_ARGS__)
  35. /**
  36. * Debug logging shorthand
  37. */
  38. #define LOG_DEBUG(...) \
  39. LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
  40. /**
  41. * Information we track for a peer in the testbed.
  42. */
  43. struct NSEPeer
  44. {
  45. /**
  46. * Prev reference in DLL.
  47. */
  48. struct NSEPeer *prev;
  49. /**
  50. * Next reference in DLL.
  51. */
  52. struct NSEPeer *next;
  53. /**
  54. * Handle with testbed.
  55. */
  56. struct GNUNET_TESTBED_Peer *daemon;
  57. /**
  58. * Testbed operation to connect to NSE service.
  59. */
  60. struct GNUNET_TESTBED_Operation *nse_op;
  61. /**
  62. * Testbed operation to connect to statistics service
  63. */
  64. struct GNUNET_TESTBED_Operation *stat_op;
  65. /**
  66. * Handle to the statistics service
  67. */
  68. struct GNUNET_STATISTICS_Handle *sh;
  69. };
  70. /**
  71. * Operation map entry
  72. */
  73. struct OpListEntry
  74. {
  75. /**
  76. * DLL next ptr
  77. */
  78. struct OpListEntry *next;
  79. /**
  80. * DLL prev ptr
  81. */
  82. struct OpListEntry *prev;
  83. /**
  84. * The testbed operation
  85. */
  86. struct GNUNET_TESTBED_Operation *op;
  87. /**
  88. * Depending on whether we start or stop NSE service at the peer set this to 1
  89. * or -1
  90. */
  91. int delta;
  92. };
  93. /**
  94. * Head of DLL of peers we monitor closely.
  95. */
  96. static struct NSEPeer *peer_head;
  97. /**
  98. * Tail of DLL of peers we monitor closely.
  99. */
  100. static struct NSEPeer *peer_tail;
  101. /**
  102. * Return value from 'main' (0 == success)
  103. */
  104. static int ok;
  105. /**
  106. * Be verbose (configuration option)
  107. */
  108. static unsigned int verbose;
  109. /**
  110. * Name of the file with the hosts to run the test over (configuration option)
  111. */
  112. static char *hosts_file;
  113. /**
  114. * Maximum number of peers in the test.
  115. */
  116. static unsigned int num_peers;
  117. /**
  118. * Total number of rounds to execute.
  119. */
  120. static unsigned int num_rounds;
  121. /**
  122. * Current round we are in.
  123. */
  124. static unsigned int current_round;
  125. /**
  126. * Array of size 'num_rounds' with the requested number of peers in the given round.
  127. */
  128. static unsigned int *num_peers_in_round;
  129. /**
  130. * How many peers are running right now?
  131. */
  132. static unsigned int peers_running;
  133. /**
  134. * Specification for the numbers of peers to have in each round.
  135. */
  136. static char *num_peer_spec;
  137. /**
  138. * Handles to all of the running peers.
  139. */
  140. static struct GNUNET_TESTBED_Peer **daemons;
  141. /**
  142. * Global configuration file
  143. */
  144. static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
  145. /**
  146. * Maximum number of connections to NSE services.
  147. */
  148. static unsigned int connection_limit;
  149. /**
  150. * Total number of connections in the whole network.
  151. */
  152. static unsigned int total_connections;
  153. /**
  154. * File to report results to.
  155. */
  156. static struct GNUNET_DISK_FileHandle *output_file;
  157. /**
  158. * Filename to log results to.
  159. */
  160. static char *output_filename;
  161. /**
  162. * File to log connection info, statistics to.
  163. */
  164. static struct GNUNET_DISK_FileHandle *data_file;
  165. /**
  166. * Filename to log connection info, statistics to.
  167. */
  168. static char *data_filename;
  169. /**
  170. * How long to wait before triggering next round?
  171. * Default: 60 s.
  172. */
  173. static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 };
  174. /**
  175. * DLL head for operation list
  176. */
  177. static struct OpListEntry *oplist_head;
  178. /**
  179. * DLL tail for operation list
  180. */
  181. static struct OpListEntry *oplist_tail;
  182. /**
  183. * Task running each round of the experiment.
  184. */
  185. static struct GNUNET_SCHEDULER_Task *round_task;
  186. /**
  187. * Clean up all of the monitoring connections to NSE and
  188. * STATISTICS that we keep to selected peers.
  189. */
  190. static void
  191. close_monitor_connections ()
  192. {
  193. struct NSEPeer *pos;
  194. struct OpListEntry *oplist_entry;
  195. while (NULL != (pos = peer_head))
  196. {
  197. if (NULL != pos->nse_op)
  198. GNUNET_TESTBED_operation_done (pos->nse_op);
  199. if (NULL != pos->stat_op)
  200. GNUNET_TESTBED_operation_done (pos->stat_op);
  201. GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
  202. GNUNET_free (pos);
  203. }
  204. while (NULL != (oplist_entry = oplist_head))
  205. {
  206. GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, oplist_entry);
  207. GNUNET_TESTBED_operation_done (oplist_entry->op);
  208. GNUNET_free (oplist_entry);
  209. }
  210. }
  211. /**
  212. * Task run on shutdown; cleans up everything.
  213. *
  214. * @param cls unused
  215. */
  216. static void
  217. shutdown_task (void *cls)
  218. {
  219. LOG_DEBUG ("Ending test.\n");
  220. close_monitor_connections ();
  221. if (NULL != round_task)
  222. {
  223. GNUNET_SCHEDULER_cancel (round_task);
  224. round_task = NULL;
  225. }
  226. if (NULL != data_file)
  227. {
  228. GNUNET_DISK_file_close (data_file);
  229. data_file = NULL;
  230. }
  231. if (NULL != output_file)
  232. {
  233. GNUNET_DISK_file_close (output_file);
  234. output_file = NULL;
  235. }
  236. if (NULL != testing_cfg)
  237. {
  238. GNUNET_CONFIGURATION_destroy (testing_cfg);
  239. testing_cfg = NULL;
  240. }
  241. }
  242. /**
  243. * Callback to call when network size estimate is updated.
  244. *
  245. * @param cls closure with the 'struct NSEPeer' providing the update
  246. * @param timestamp server timestamp
  247. * @param estimate the value of the current network size estimate
  248. * @param std_dev standard deviation (rounded down to nearest integer)
  249. * of the size estimation values seen
  250. */
  251. static void
  252. handle_estimate (void *cls,
  253. struct GNUNET_TIME_Absolute timestamp,
  254. double estimate, double std_dev)
  255. {
  256. struct NSEPeer *peer = cls;
  257. char output_buffer[512];
  258. size_t size;
  259. if (NULL == output_file)
  260. {
  261. FPRINTF (stderr,
  262. "Received network size estimate from peer %p. Size: %f std.dev. %f\n",
  263. peer, estimate, std_dev);
  264. return;
  265. }
  266. size = GNUNET_snprintf (output_buffer,
  267. sizeof (output_buffer),
  268. "%p %llu %llu %f %f %f\n",
  269. peer, peers_running,
  270. (unsigned long long) timestamp.abs_value_us,
  271. GNUNET_NSE_log_estimate_to_n (estimate), estimate,
  272. std_dev);
  273. if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
  274. GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
  275. "Unable to write to file!\n");
  276. }
  277. /**
  278. * Adapter function called to establish a connection to
  279. * NSE service.
  280. *
  281. * @param cls closure (the 'struct NSEPeer')
  282. * @param cfg configuration of the peer to connect to; will be available until
  283. * GNUNET_TESTBED_operation_done() is called on the operation returned
  284. * from GNUNET_TESTBED_service_connect()
  285. * @return service handle to return in 'op_result', NULL on error
  286. */
  287. static void *
  288. nse_connect_adapter (void *cls,
  289. const struct GNUNET_CONFIGURATION_Handle *cfg)
  290. {
  291. struct NSEPeer *current_peer = cls;
  292. return GNUNET_NSE_connect (cfg, &handle_estimate, current_peer);
  293. }
  294. /**
  295. * Adapter function called to destroy a connection to
  296. * NSE service.
  297. *
  298. * @param cls closure
  299. * @param op_result service handle returned from the connect adapter
  300. */
  301. static void
  302. nse_disconnect_adapter (void *cls,
  303. void *op_result)
  304. {
  305. GNUNET_NSE_disconnect (op_result);
  306. }
  307. /**
  308. * Callback function to process statistic values.
  309. *
  310. * @param cls `struct NSEPeer`
  311. * @param subsystem name of subsystem that created the statistic
  312. * @param name the name of the datum
  313. * @param value the current value
  314. * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
  315. * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
  316. */
  317. static int
  318. stat_iterator (void *cls,
  319. const char *subsystem,
  320. const char *name,
  321. uint64_t value,
  322. int is_persistent)
  323. {
  324. char *output_buffer;
  325. struct GNUNET_TIME_Absolute now;
  326. int size;
  327. unsigned int flag;
  328. GNUNET_assert (NULL != data_file);
  329. now = GNUNET_TIME_absolute_get ();
  330. flag = strcasecmp (subsystem, "core");
  331. if (0 != flag)
  332. flag = 1;
  333. size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n",
  334. now.abs_value_us / 1000LL / 1000LL,
  335. value, flag);
  336. if (0 > size)
  337. {
  338. GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n");
  339. GNUNET_free (output_buffer);
  340. return GNUNET_SYSERR;
  341. }
  342. if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size))
  343. {
  344. GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
  345. GNUNET_free (output_buffer);
  346. return GNUNET_SYSERR;
  347. }
  348. GNUNET_free (output_buffer);
  349. return GNUNET_OK;
  350. }
  351. /**
  352. * Called to open a connection to the peer's statistics
  353. *
  354. * @param cls peer context
  355. * @param cfg configuration of the peer to connect to; will be available until
  356. * GNUNET_TESTBED_operation_done() is called on the operation returned
  357. * from GNUNET_TESTBED_service_connect()
  358. * @return service handle to return in 'op_result', NULL on error
  359. */
  360. static void *
  361. stat_connect_adapter (void *cls,
  362. const struct GNUNET_CONFIGURATION_Handle *cfg)
  363. {
  364. struct NSEPeer *peer = cls;
  365. peer->sh = GNUNET_STATISTICS_create ("nse-profiler", cfg);
  366. return peer->sh;
  367. }
  368. /**
  369. * Called to disconnect from peer's statistics service
  370. *
  371. * @param cls peer context
  372. * @param op_result service handle returned from the connect adapter
  373. */
  374. static void
  375. stat_disconnect_adapter (void *cls, void *op_result)
  376. {
  377. struct NSEPeer *peer = cls;
  378. GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
  379. (peer->sh, "core", "# peers connected",
  380. stat_iterator, peer));
  381. GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
  382. (peer->sh, "nse", "# peers connected",
  383. stat_iterator, peer));
  384. GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
  385. peer->sh = NULL;
  386. }
  387. /**
  388. * Called after successfully opening a connection to a peer's statistics
  389. * service; we register statistics monitoring for CORE and NSE here.
  390. *
  391. * @param cls the callback closure from functions generating an operation
  392. * @param op the operation that has been finished
  393. * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
  394. * @param emsg error message in case the operation has failed; will be NULL if
  395. * operation has executed successfully.
  396. */
  397. static void
  398. stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
  399. void *ca_result, const char *emsg )
  400. {
  401. struct GNUNET_STATISTICS_Handle *sh = ca_result;
  402. struct NSEPeer *peer = cls;
  403. if (NULL != emsg)
  404. {
  405. GNUNET_break (0);
  406. return;
  407. }
  408. GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
  409. (sh, "core", "# peers connected",
  410. stat_iterator, peer));
  411. GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
  412. (sh, "nse", "# peers connected",
  413. stat_iterator, peer));
  414. }
  415. /**
  416. * Task run to connect to the NSE and statistics services to a subset of
  417. * all of the running peers.
  418. */
  419. static void
  420. connect_nse_service ()
  421. {
  422. struct NSEPeer *current_peer;
  423. unsigned int i;
  424. unsigned int connections;
  425. if (0 == connection_limit)
  426. return;
  427. LOG_DEBUG ("Connecting to nse service of peers\n");
  428. connections = 0;
  429. for (i = 0; i < num_peers_in_round[current_round]; i++)
  430. {
  431. if ((num_peers_in_round[current_round] > connection_limit) &&
  432. (0 != (i % (num_peers_in_round[current_round] / connection_limit))))
  433. continue;
  434. LOG_DEBUG ("Connecting to nse service of peer %d\n", i);
  435. current_peer = GNUNET_new (struct NSEPeer);
  436. current_peer->daemon = daemons[i];
  437. current_peer->nse_op
  438. = GNUNET_TESTBED_service_connect (NULL,
  439. current_peer->daemon,
  440. "nse",
  441. NULL, NULL,
  442. &nse_connect_adapter,
  443. &nse_disconnect_adapter,
  444. current_peer);
  445. if (NULL != data_file)
  446. current_peer->stat_op
  447. = GNUNET_TESTBED_service_connect (NULL,
  448. current_peer->daemon,
  449. "statistics",
  450. stat_comp_cb,
  451. current_peer,
  452. &stat_connect_adapter,
  453. &stat_disconnect_adapter,
  454. current_peer);
  455. GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
  456. if (++connections == connection_limit)
  457. break;
  458. }
  459. }
  460. /**
  461. * Task that starts/stops peers to move to the next round.
  462. *
  463. * @param cls NULL, unused
  464. */
  465. static void
  466. next_round (void *cls);
  467. /**
  468. * We're at the end of a round. Stop monitoring, write total
  469. * number of connections to log and get full stats. Then trigger
  470. * the next round.
  471. *
  472. * @param cls unused, NULL
  473. */
  474. static void
  475. finish_round (void *cls)
  476. {
  477. LOG (GNUNET_ERROR_TYPE_INFO,
  478. "Have %u connections\n",
  479. total_connections);
  480. close_monitor_connections ();
  481. round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL);
  482. }
  483. /**
  484. * We have reached the desired number of peers for the current round.
  485. * Run it (by connecting and monitoring a few peers and waiting the
  486. * specified delay before finishing the round).
  487. */
  488. static void
  489. run_round ()
  490. {
  491. LOG_DEBUG ("Running round %u\n",
  492. current_round);
  493. connect_nse_service ();
  494. GNUNET_SCHEDULER_add_delayed (wait_time,
  495. &finish_round,
  496. NULL);
  497. }
  498. /**
  499. * Creates an oplist entry and adds it to the oplist DLL
  500. */
  501. static struct OpListEntry *
  502. make_oplist_entry ()
  503. {
  504. struct OpListEntry *entry;
  505. entry = GNUNET_new (struct OpListEntry);
  506. GNUNET_CONTAINER_DLL_insert_tail (oplist_head,
  507. oplist_tail,
  508. entry);
  509. return entry;
  510. }
  511. /**
  512. * Callback to be called when NSE service is started or stopped at peers
  513. *
  514. * @param cls NULL
  515. * @param op the operation handle
  516. * @param emsg NULL on success; otherwise an error description
  517. */
  518. static void
  519. manage_service_cb (void *cls,
  520. struct GNUNET_TESTBED_Operation *op,
  521. const char *emsg)
  522. {
  523. struct OpListEntry *entry = cls;
  524. GNUNET_TESTBED_operation_done (entry->op);
  525. if (NULL != emsg)
  526. {
  527. LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n");
  528. GNUNET_SCHEDULER_shutdown ();
  529. return;
  530. }
  531. GNUNET_assert (0 != entry->delta);
  532. peers_running += entry->delta;
  533. GNUNET_CONTAINER_DLL_remove (oplist_head,
  534. oplist_tail,
  535. entry);
  536. GNUNET_free (entry);
  537. if (num_peers_in_round[current_round] == peers_running)
  538. run_round ();
  539. }
  540. /**
  541. * Adjust the number of running peers to match the required number of running
  542. * peers for the round
  543. */
  544. static void
  545. adjust_running_peers ()
  546. {
  547. struct OpListEntry *entry;
  548. unsigned int i;
  549. /* start peers if we have too few */
  550. for (i=peers_running;i<num_peers_in_round[current_round];i++)
  551. {
  552. entry = make_oplist_entry ();
  553. entry->delta = 1;
  554. entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
  555. daemons[i],
  556. "nse",
  557. &manage_service_cb,
  558. entry,
  559. 1);
  560. }
  561. /* stop peers if we have too many */
  562. for (i=num_peers_in_round[current_round];i<peers_running;i++)
  563. {
  564. entry = make_oplist_entry ();
  565. entry->delta = -1;
  566. entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
  567. daemons[i],
  568. "nse",
  569. &manage_service_cb,
  570. entry,
  571. 0);
  572. }
  573. }
  574. /**
  575. * Task run at the end of a round. Disconnect from all monitored
  576. * peers; then get statistics from *all* peers.
  577. *
  578. * @param cls NULL, unused
  579. */
  580. static void
  581. next_round (void *cls)
  582. {
  583. round_task = NULL;
  584. LOG_DEBUG ("Disconnecting nse service of peers\n");
  585. current_round++;
  586. if (current_round == num_rounds)
  587. {
  588. /* this was the last round, terminate */
  589. ok = 0;
  590. GNUNET_SCHEDULER_shutdown ();
  591. return;
  592. }
  593. if (num_peers_in_round[current_round] == peers_running)
  594. {
  595. /* no need to churn, just run next round */
  596. run_round ();
  597. return;
  598. }
  599. adjust_running_peers ();
  600. }
  601. /**
  602. * Function that will be called whenever something in the
  603. * testbed changes.
  604. *
  605. * @param cls closure, NULL
  606. * @param event information on what is happening
  607. */
  608. static void
  609. master_controller_cb (void *cls,
  610. const struct GNUNET_TESTBED_EventInformation *event)
  611. {
  612. switch (event->type)
  613. {
  614. case GNUNET_TESTBED_ET_CONNECT:
  615. total_connections++;
  616. break;
  617. case GNUNET_TESTBED_ET_DISCONNECT:
  618. total_connections--;
  619. break;
  620. default:
  621. break;
  622. }
  623. }
  624. /**
  625. * Signature of a main function for a testcase.
  626. *
  627. * @param cls NULL
  628. * @param h the run handle
  629. * @param num_peers_ number of peers in 'peers'
  630. * @param peers handle to peers run in the testbed. NULL upon timeout (see
  631. * GNUNET_TESTBED_test_run()).
  632. * @param links_succeeded the number of overlay link connection attempts that
  633. * succeeded
  634. * @param links_failed the number of overlay link connection attempts that
  635. * failed
  636. */
  637. static void
  638. test_master (void *cls,
  639. struct GNUNET_TESTBED_RunHandle *h,
  640. unsigned int num_peers_,
  641. struct GNUNET_TESTBED_Peer **peers,
  642. unsigned int links_succeeded,
  643. unsigned int links_failed)
  644. {
  645. if (NULL == peers)
  646. {
  647. GNUNET_SCHEDULER_shutdown ();
  648. return;
  649. }
  650. daemons = peers;
  651. GNUNET_break (num_peers_ == num_peers);
  652. peers_running = num_peers;
  653. if (num_peers_in_round[current_round] == peers_running)
  654. {
  655. /* no need to churn, just run the starting round */
  656. run_round ();
  657. return;
  658. }
  659. adjust_running_peers ();
  660. }
  661. /**
  662. * Actual main function that runs the emulation.
  663. *
  664. * @param cls unused
  665. * @param args remaining args, unused
  666. * @param cfgfile name of the configuration
  667. * @param cfg configuration handle
  668. */
  669. static void
  670. run (void *cls, char *const *args, const char *cfgfile,
  671. const struct GNUNET_CONFIGURATION_Handle *cfg)
  672. {
  673. char *tok;
  674. uint64_t event_mask;
  675. unsigned int num;
  676. ok = 1;
  677. testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
  678. LOG_DEBUG ("Starting daemons.\n");
  679. if (NULL == num_peer_spec)
  680. {
  681. fprintf (stderr, "You need to specify the number of peers to run\n");
  682. return;
  683. }
  684. for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ","))
  685. {
  686. if (1 != sscanf (tok, "%u", &num))
  687. {
  688. fprintf (stderr, "You need to specify numbers, not `%s'\n", tok);
  689. return;
  690. }
  691. if (0 == num)
  692. {
  693. fprintf (stderr, "Refusing to run a round with 0 peers\n");
  694. return;
  695. }
  696. GNUNET_array_append (num_peers_in_round, num_rounds, num);
  697. num_peers = GNUNET_MAX (num_peers, num);
  698. }
  699. if (0 == num_peers)
  700. {
  701. fprintf (stderr, "Refusing to run a testbed with no rounds\n");
  702. return;
  703. }
  704. if ( (NULL != data_filename) &&
  705. (NULL == (data_file =
  706. GNUNET_DISK_file_open (data_filename,
  707. GNUNET_DISK_OPEN_READWRITE |
  708. GNUNET_DISK_OPEN_TRUNCATE |
  709. GNUNET_DISK_OPEN_CREATE,
  710. GNUNET_DISK_PERM_USER_READ |
  711. GNUNET_DISK_PERM_USER_WRITE))) )
  712. GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
  713. "open",
  714. data_filename);
  715. if ( (NULL != output_filename) &&
  716. (NULL == (output_file =
  717. GNUNET_DISK_file_open (output_filename,
  718. GNUNET_DISK_OPEN_READWRITE |
  719. GNUNET_DISK_OPEN_CREATE,
  720. GNUNET_DISK_PERM_USER_READ |
  721. GNUNET_DISK_PERM_USER_WRITE))) )
  722. GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open",
  723. output_filename);
  724. event_mask = 0LL;
  725. event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
  726. event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
  727. event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
  728. event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
  729. GNUNET_TESTBED_run (hosts_file,
  730. cfg,
  731. num_peers,
  732. event_mask,
  733. master_controller_cb,
  734. NULL, /* master_controller_cb cls */
  735. &test_master,
  736. NULL); /* test_master cls */
  737. GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
  738. }
  739. /**
  740. * Main function.
  741. *
  742. * @return 0 on success
  743. */
  744. int
  745. main (int argc, char *const *argv)
  746. {
  747. struct GNUNET_GETOPT_CommandLineOption options[] = {
  748. GNUNET_GETOPT_option_uint ('C',
  749. "connections",
  750. "COUNT",
  751. gettext_noop ("limit to the number of connections to NSE services, 0 for none"),
  752. &connection_limit),
  753. GNUNET_GETOPT_option_string ('d',
  754. "details",
  755. "FILENAME",
  756. gettext_noop ("name of the file for writing connection information and statistics"),
  757. &data_filename),
  758. GNUNET_GETOPT_option_string ('H',
  759. "hosts",
  760. "FILENAME",
  761. gettext_noop ("name of the file with the login information for the testbed"),
  762. &hosts_file),
  763. GNUNET_GETOPT_option_string ('o',
  764. "output",
  765. "FILENAME",
  766. gettext_noop ("name of the file for writing the main results"),
  767. &output_filename),
  768. GNUNET_GETOPT_option_string ('p',
  769. "peers",
  770. "NETWORKSIZESPEC",
  771. gettext_noop ("Number of peers to run in each round, separated by commas"),
  772. &num_peer_spec),
  773. GNUNET_GETOPT_option_increment_uint ('V',
  774. "verbose",
  775. gettext_noop ("be verbose (print progress information)"),
  776. &verbose),
  777. GNUNET_GETOPT_option_relative_time ('w',
  778. "wait",
  779. "DELAY",
  780. gettext_noop ("delay between rounds"),
  781. &wait_time),
  782. GNUNET_GETOPT_OPTION_END
  783. };
  784. if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
  785. return 2;
  786. if (GNUNET_OK !=
  787. GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
  788. gettext_noop
  789. ("Measure quality and performance of the NSE service."),
  790. options, &run, NULL))
  791. ok = 1;
  792. return ok;
  793. }
  794. /* end of nse-profiler.c */