73871c0537e8af6009cce6ac2ecb296621a7c8da
[oweals/gnunet.git] / src / ats / perf_ats_solver.c
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010,2011 GNUnet e.V.
4
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Affero General Public License for more details.
14
15  You should have received a copy of the GNU Affero General Public License
16  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /**
19  * @file ats/perf_ats_solver.c
20  * @brief generic performance test for ATS solvers
21  * @author Christian Grothoff
22  * @author Matthias Wachs
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26 #include "gnunet_statistics_service.h"
27 #include "gnunet-service-ats_addresses.h"
28 #include "gnunet-service-ats_plugins.h"
29 #include "gnunet-service-ats_normalization.h"
30 #include "gnunet-service-ats_preferences.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet_ats_plugin.h"
33 #include "test_ats_api_common.h"
34
35 #define DEFAULT_UPDATE_PERCENTAGE       20
36 #define DEFAULT_PEERS_START     10
37 #define DEFAULT_PEERS_END       10
38 #define DEFAULT_ADDRESSES       10
39 #define DEFAULT_ATS_COUNT       2
40
41
42 /**
43  * Handle for statistics.
44  */
45 struct GNUNET_STATISTICS_Handle *GSA_stats;
46
47 /**
48  * Handle for ATS address component
49  */
50 struct PerfHandle
51 {
52   /**
53    * Performance peers
54    */
55   struct PerfPeer *peers;
56
57   /**
58    *  Solver handle
59    */
60   struct GNUNET_ATS_SolverFunctions *sf;
61
62   /**
63    * Statistics stat;
64    */
65   struct GNUNET_STATISTICS_Handle *stat;
66
67   /**
68    * A multihashmap to store all addresses
69    */
70   struct GNUNET_CONTAINER_MultiPeerMap *addresses;
71
72   /**
73    * Solver functions
74    * */
75   struct GNUNET_ATS_PluginEnvironment env;
76
77   /**
78    * Array for results for each iteration with length iterations
79    */
80   struct Iteration *iterations_results;
81
82   /**
83    * The current result
84    */
85   struct Result *current_result;
86
87   /**
88    * Current number of peers benchmarked
89    */
90   int current_p;
91
92   /**
93    * Current number of addresses benchmarked
94    */
95   int current_a;
96
97   /**
98    * Solver description as string
99    */
100   char *ats_string;
101
102   /**
103    * Configured ATS solver
104    */
105   int ats_mode;
106
107   /**
108    * #peers to start benchmarking with
109    */
110   int N_peers_start;
111
112   /**
113    * #peers to end benchmarking with
114    */
115   int N_peers_end;
116
117   /**
118    * #addresses to benchmarking with
119    */
120   int N_address;
121
122   /**
123    * Percentage of peers to update
124    */
125   int opt_update_percent;
126
127   /**
128    * Create gnuplot file
129    */
130   int create_datafile;
131
132   /**
133    * Measure updates
134    */
135   int measure_updates;
136
137   /**
138    * Number of iterations
139    */
140   int total_iterations;
141
142   /**
143    * Current iteration
144    */
145   int current_iteration;
146
147   /**
148    * Is a bulk operation running?
149    */
150   int bulk_running;
151
152   /**
153    * Is a bulk operation running?
154    */
155   int expecting_solution;
156
157   /**
158    * Was the problem just updates?
159    */
160   int performed_update;
161 };
162
163 /**
164  * Data structure to store results for a single iteration
165  */
166 struct Iteration
167 {
168   struct Result **results_array;
169
170   struct Result **update_results_array;
171 };
172
173
174 /**
175  * Result for a solver calculcation
176  */
177 struct Result
178 {
179   /**
180    * Previous element in the linked list
181    */
182   struct Result *prev;
183
184   /**
185    * Next element in the linked list
186    */
187   struct Result *next;
188
189   /**
190    * Number of peers this solution included
191    */
192   int peers;
193
194   /**
195    * Number of addresses per peer this solution included
196    */
197   int addresses;
198
199   /**
200    * Is this an update or a full solution
201    */
202   int update;
203
204   /**
205    * Was the solution valid or did the solver fail
206    */
207   int valid;
208
209   /**
210    * Result of the solver
211    */
212   enum GAS_Solver_Additional_Information info;
213
214   /**
215    * Duration of setting up the problem in the solver
216    */
217   struct GNUNET_TIME_Relative d_setup_full;
218
219   /**
220    * Duration of solving the LP problem in the solver
221    * MLP solver only
222    */
223   struct GNUNET_TIME_Relative d_lp_full;
224
225   /**
226    * Duration of solving the MLP problem in the solver
227    * MLP solver only
228    */
229   struct GNUNET_TIME_Relative d_mlp_full;
230
231   /**
232    * Duration of solving whole problem in the solver
233    */
234   struct GNUNET_TIME_Relative d_total_full;
235
236   /**
237    * Start time of setting up the problem in the solver
238    */
239   struct GNUNET_TIME_Absolute s_setup;
240
241   /**
242    * Start time of solving the LP problem in the solver
243    * MLP solver only
244    */
245   struct GNUNET_TIME_Absolute s_lp;
246
247   /**
248    * Start time of solving the MLP problem in the solver
249    * MLP solver only
250    */
251   struct GNUNET_TIME_Absolute s_mlp;
252
253   /**
254    * Start time of solving whole problem in the solver
255    */
256   struct GNUNET_TIME_Absolute s_total;
257
258   /**
259    * End time of setting up the problem in the solver
260    */
261   struct GNUNET_TIME_Absolute e_setup;
262
263   /**
264    * End time of solving the LP problem in the solver
265    * MLP solver only
266    */
267   struct GNUNET_TIME_Absolute e_lp;
268
269   /**
270    * End time of solving the MLP problem in the solver
271    * MLP solver only
272    */
273   struct GNUNET_TIME_Absolute e_mlp;
274
275   /**
276    * End time of solving whole problem in the solver
277    */
278   struct GNUNET_TIME_Absolute e_total;
279 };
280
281 /**
282  * Peer used for the benchmarking
283  */
284 struct PerfPeer
285 {
286   /**
287    * Peer identitity
288    */
289   struct GNUNET_PeerIdentity id;
290
291   /**
292    * Head of linked list of addresses used with this peer
293    */
294   struct ATS_Address *head;
295
296   /**
297    * Head of linked list of addresses used with this peer
298    */
299   struct ATS_Address *tail;
300 };
301
302
303 /**
304  * ATS performance handle
305  */
306 static struct PerfHandle ph;
307
308 /**
309  * Return value
310  */
311 static int ret;
312
313
314 /**
315  * Do shutdown
316  */
317 static void
318 end_now (int res)
319 {
320   if (NULL != ph.stat)
321   {
322     GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
323     ph.stat = NULL;
324   }
325
326   GNUNET_free_non_null (ph.peers);
327   GNUNET_free_non_null (ph.iterations_results);
328
329   GAS_normalization_stop ();
330   GAS_preference_done ();
331   ret = res;
332 }
333
334
335 /**
336  * Create a peer used for benchmarking
337  *
338  * @param cp the number of the peer
339  */
340 static void
341 perf_create_peer (int cp)
342 {
343
344   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
345       &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity));
346   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
347       GNUNET_i2s (&ph.peers[cp].id));
348 }
349
350
351 /**
352  * Perform an update for an address
353  *
354  * @param cur the address to update
355  */
356 static void
357 perf_update_address (struct ATS_Address *cur)
358 {
359   int r_type;
360   int abs_val;
361   double rel_val;
362
363   r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
364   switch (r_type)
365   {
366   case 0:
367     abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
368     rel_val = (100 + (double) abs_val) / 100;
369
370     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
371         "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
372         GNUNET_i2s (&cur->peer), cur,
373         "GNUNET_ATS_QUALITY_NET_DELAY",
374         abs_val, rel_val);
375     ph.sf->s_address_update_property (ph.sf->cls, cur,
376         GNUNET_ATS_QUALITY_NET_DELAY,
377         abs_val, rel_val);
378     break;
379   case 1:
380     abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
381     rel_val = (100 + (double) abs_val) / 100;
382
383     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
384         "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
385         GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
386         abs_val, rel_val);
387     ph.sf->s_address_update_property (ph.sf->cls, cur,
388         GNUNET_ATS_QUALITY_NET_DISTANCE,
389         abs_val, rel_val);
390     break;
391   default:
392     break;
393   }
394 }
395
396
397 static void
398 bandwidth_changed_cb (void *cls,
399                       struct ATS_Address *address)
400 {
401   if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
402     return;
403
404   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405               "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
406               GNUNET_i2s (&address->peer),
407               address,
408               address->assigned_bw_out,
409               address->assigned_bw_in);
410   if (GNUNET_YES == ph.bulk_running)
411     GNUNET_break (0);
412   return;
413 }
414
415
416 static const double *
417 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
418 {
419   return GAS_preference_get_by_peer (NULL, id);
420 }
421
422
423 static void
424 perf_address_initial_update (void *dead,
425     struct GNUNET_CONTAINER_MultiPeerMap * addresses,
426     struct ATS_Address *address)
427 {
428   double delay;
429   double distance;
430   uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
431   delay = (100 + (double) random) / 100;
432   ph.sf->s_address_update_property (ph.sf->cls,
433                                     address, GNUNET_ATS_QUALITY_NET_DELAY,
434       100,  delay);
435
436   random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
437   distance = (100 + (double) random) / 100;
438
439   ph.sf->s_address_update_property (ph.sf->cls, address,
440                                     GNUNET_ATS_QUALITY_NET_DISTANCE,
441                                     10, distance);
442
443   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
444              "Initial update address %p : %.2f  %.2f\n",
445              address, delay, distance);
446 }
447
448
449 struct DUA_Ctx
450 {
451   int r;
452   int c_cur_a;
453 };
454
455
456 static int
457 do_update_address (void *cls,
458                    const struct GNUNET_PeerIdentity *pid,
459                    void *value)
460 {
461   struct DUA_Ctx *ctx = cls;
462   struct ATS_Address *addr = value;
463
464   if (ctx->c_cur_a == ctx->r)
465     perf_update_address (addr);
466   ctx->c_cur_a++;
467   return GNUNET_OK;
468 }
469
470
471 /**
472  * Update a certain percentage of peers
473  *
474  * @param cp the current number of peers
475  * @param ca the current number of addresses
476  * @param percentage_peers the percentage of peers to update
477  */
478 static void
479 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
480 {
481   int c_peer;
482   int c_select;
483   int c_cur_p;
484   int r;
485   int count;
486   unsigned int m[cp];
487   struct DUA_Ctx dua_ctx;
488
489   count = cp * ((double) percentage_peers / 100);
490   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
491       "Updating %u of %u peers \n", count, cp);
492
493   for (c_peer = 0; c_peer < cp; c_peer++)
494     m[c_peer] = 0;
495
496   c_select = 0;
497
498   while (c_select < count)
499   {
500     r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
501     if (0 == m[r])
502     {
503       m[r] = 1;
504       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
505           "Updating peer [%u] \n", r);
506       c_select++;
507     }
508   }
509   for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
510   {
511     if (1 == m[c_cur_p])
512     {
513       r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
514       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
515                  "Updating peer [%u] address [%u]\n", c_cur_p, r);
516
517       dua_ctx.c_cur_a = 0;
518       dua_ctx.r = r;
519       GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
520                                                   &ph.peers[c_cur_p].id,
521                                                   &do_update_address,
522                                                   &dua_ctx);
523     }
524   }
525 }
526
527 /**
528  * Create an address for a peer
529  *
530  * @param cp index of the peer
531  * @param ca index of the address
532  * @return the address
533  */
534 static struct ATS_Address *
535 perf_create_address (int cp, int ca)
536 {
537   struct ATS_Address *a;
538
539   a = create_address (&ph.peers[cp].id,
540       "Test 1", "test 1", strlen ("test 1") + 1, 0);
541   GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
542       GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
543   return a;
544 }
545
546
547 /**
548  * Information callback for the solver
549  *
550  * @param op the solver operation
551  * @param stat status of the solver operation
552  * @param add additional solver information
553  */
554 static void
555 solver_info_cb (void *cls,
556     enum GAS_Solver_Operation op,
557     enum GAS_Solver_Status stat,
558     enum GAS_Solver_Additional_Information add)
559 {
560   char *add_info;
561   switch (add) {
562     case GAS_INFO_NONE:
563       add_info = "GAS_INFO_NONE";
564       break;
565     case GAS_INFO_FULL:
566       add_info = "GAS_INFO_MLP_FULL";
567       break;
568     case GAS_INFO_UPDATED:
569       add_info = "GAS_INFO_MLP_UPDATED";
570       break;
571     case GAS_INFO_PROP_ALL:
572       add_info = "GAS_INFO_PROP_ALL";
573       break;
574     case GAS_INFO_PROP_SINGLE:
575       add_info = "GAS_INFO_PROP_SINGLE";
576       break;
577     default:
578       add_info = "INVALID";
579       break;
580   }
581
582   struct Result *tmp;
583   switch (op)
584   {
585     case GAS_OP_SOLVE_START:
586       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
587           "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
588           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
589       if (GNUNET_NO == ph.expecting_solution)
590       {
591         /* We do not expect a solution at the moment */
592         GNUNET_break (0);
593         return;
594       }
595
596       if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
597       {
598         tmp = GNUNET_new (struct Result);
599         /* Create new result */
600         if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
601         {
602           ph.current_result = tmp;
603           //fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p);
604           ph.iterations_results[ph.current_iteration-1].update_results_array[ph.current_p] = tmp;
605         }
606         else
607         {
608           ph.current_result = tmp;
609           //fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p);
610           ph.iterations_results[ph.current_iteration-1].results_array[ph.current_p] = tmp;
611         }
612
613         ph.current_result->addresses = ph.current_a;
614         ph.current_result->peers = ph.current_p;
615         ph.current_result->s_total = GNUNET_TIME_absolute_get();
616         ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL;
617         ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL;
618         ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL;
619         ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL;
620         ph.current_result->info = add;
621         if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
622         {
623           ph.current_result->update = GNUNET_YES;
624         }
625         else
626         {
627           ph.current_result->update = GNUNET_NO;
628         }
629
630       }
631       return;
632     case GAS_OP_SOLVE_STOP:
633       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
634           "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP",
635           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
636       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
637       {
638         /* We do not expect a solution at the moment */
639         GNUNET_break (0);
640         return;
641       }
642
643       if (GAS_STAT_SUCCESS == stat)
644         ph.current_result->valid = GNUNET_YES;
645       else
646         ph.current_result->valid = GNUNET_NO;
647
648       if (NULL != ph.current_result)
649       {
650         /* Finalize result */
651         ph.current_result->e_total = GNUNET_TIME_absolute_get ();
652         ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference (
653             ph.current_result->s_total, ph.current_result->e_total);
654       }
655       ph.current_result = NULL;
656       return;
657
658     case GAS_OP_SOLVE_SETUP_START:
659       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
660           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
661           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
662       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
663       {
664         GNUNET_break(0);
665         return;
666       }
667
668       if (GAS_STAT_SUCCESS == stat)
669         ph.current_result->valid = GNUNET_YES;
670       else
671         ph.current_result->valid = GNUNET_NO;
672
673       ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
674       return;
675
676     case GAS_OP_SOLVE_SETUP_STOP:
677       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
678           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
679           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
680       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
681       {
682         GNUNET_break(0);
683         return;
684       }
685
686       if (GAS_STAT_SUCCESS == stat)
687         ph.current_result->valid = GNUNET_YES;
688       else
689         ph.current_result->valid = GNUNET_NO;
690
691       ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
692       ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference (
693           ph.current_result->s_setup, ph.current_result->e_setup);
694       return;
695
696     case GAS_OP_SOLVE_MLP_LP_START:
697       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
698           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
699           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
700       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
701       {
702         GNUNET_break(0);
703         return;
704       }
705
706       if (GAS_STAT_SUCCESS == stat)
707         ph.current_result->valid = GNUNET_YES;
708       else
709         ph.current_result->valid = GNUNET_NO;
710
711       ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
712       return;
713     case GAS_OP_SOLVE_MLP_LP_STOP:
714       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
715           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
716           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
717       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
718       {
719         GNUNET_break(0);
720         return;
721       }
722
723       if (GAS_STAT_SUCCESS == stat)
724         ph.current_result->valid = GNUNET_YES;
725       else
726         ph.current_result->valid = GNUNET_NO;
727
728       ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
729       ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference (
730           ph.current_result->s_lp, ph.current_result->e_lp);
731       return;
732
733     case GAS_OP_SOLVE_MLP_MLP_START:
734       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
735           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
736           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
737       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
738       {
739         GNUNET_break(0);
740         return;
741       }
742
743       if (GAS_STAT_SUCCESS == stat)
744         ph.current_result->valid = GNUNET_YES;
745       else
746         ph.current_result->valid = GNUNET_NO;
747
748       ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
749       return;
750     case GAS_OP_SOLVE_MLP_MLP_STOP:
751       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
752           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
753           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
754       if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
755       {
756         GNUNET_break(0);
757         return;
758       }
759
760       if (GAS_STAT_SUCCESS == stat)
761         ph.current_result->valid = GNUNET_YES;
762       else
763         ph.current_result->valid = GNUNET_NO;
764
765       ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
766       ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference (
767       ph.current_result->s_mlp, ph.current_result->e_mlp);
768       return;
769     case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
770       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
771           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
772           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
773       return;
774     case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
775       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
776           "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
777           (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
778       if (GAS_STAT_SUCCESS != stat)
779       {
780         GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
781             "Solver `%s' failed to update problem with %u peers and %u address!\n",
782             ph.ats_string, ph.current_p, ph.current_a);
783       }
784
785       return;
786     default:
787       break;
788     }
789 }
790
791 /**
792  * Evaluate results for a specific iteration
793  *
794  * @param iteration the iteration to evaluate
795  */
796 static void
797 evaluate (int iteration)
798 {
799   struct Result *cur;
800   int cp;
801
802   for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp ++)
803   {
804     cur = ph.iterations_results[ph.current_iteration-1].results_array[cp];
805     if (0 == cp)
806       continue;
807     if (NULL == cur)
808     {
809       GNUNET_break (0);
810       fprintf (stderr,
811                "Missing result for %u peers\n", cp);
812       continue;
813     }
814
815
816     if (GNUNET_NO == cur->valid)
817     {
818       fprintf (stderr,
819                "Total time to solve %s for %u peers %u addresses: %s\n",
820                (GNUNET_YES == cur->update) ? "updated" : "full",
821                cur->peers, cur->addresses, "Failed to solve!");
822       continue;
823     }
824
825
826     if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us)
827     {
828       fprintf (stderr,
829          "Total time to solve %s for %u peers %u addresses: %llu us\n",
830          (GNUNET_YES == cur->update) ? "updated" : "full",
831          cur->peers, cur->addresses,
832          (unsigned long long) cur->d_total_full.rel_value_us);
833     }
834
835
836     if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us)
837     {
838       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
839           "Total time to setup %s %u peers %u addresses: %llu us\n",
840           (GNUNET_YES == cur->update) ? "updated" : "full",
841           cur->peers, cur->addresses,
842           (unsigned long long) cur->d_setup_full.rel_value_us);
843     }
844
845     if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us)
846     {
847       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
848          "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
849          (GNUNET_YES == cur->update) ? "updated" : "full",
850          cur->peers,
851          cur->addresses,
852          (unsigned long long )cur->d_lp_full.rel_value_us);
853     }
854
855     if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us)
856     {
857       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
858           "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
859           (GNUNET_YES == cur->update) ? "updated" : "full",
860           cur->peers, cur->addresses,
861           (unsigned long long )cur->d_mlp_full.rel_value_us);
862     }
863   }
864 }
865
866
867 static unsigned int
868 get_connectivity_cb (void *cls,
869                      const struct GNUNET_PeerIdentity *peer)
870 {
871   return GNUNET_CONTAINER_multipeermap_contains (ph.addresses,
872                                                  peer);
873 }
874
875
876 /**
877  * Evaluate average results for all iterations
878  */
879 static void
880 write_all_iterations (void)
881 {
882   int c_iteration;
883   int c_peer;
884
885   struct GNUNET_DISK_FileHandle *f_full;
886   struct GNUNET_DISK_FileHandle *f_update;
887   char * data_fn_full;
888   char * data_fn_update;
889   char * data;
890
891   f_full = NULL;
892   f_update = NULL;
893
894   data_fn_full = NULL;
895
896   if (GNUNET_NO == ph.create_datafile)
897     return;
898
899   GNUNET_asprintf (&data_fn_full,
900                    "perf_%s_full_%u-%u_%u_%u.data",
901                    ph.ats_string,
902                    ph.total_iterations,
903                    ph.N_peers_start,
904                    ph.N_peers_end,
905                    ph.N_address);
906   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
907               "Using data file `%s'\n",
908               data_fn_full);
909
910   f_full = GNUNET_DISK_file_open (data_fn_full,
911       GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
912       GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
913   if (NULL == f_full)
914   {
915     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
916                 "Cannot open data file `%s'\n",
917                 data_fn_full);
918     GNUNET_free (data_fn_full);
919     return;
920   }
921
922   data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
923   if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data)))
924     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
925                 "Cannot write data to log file `%s'\n",
926                 data_fn_full);
927
928   data_fn_update = NULL;
929   if (GNUNET_YES == ph.measure_updates)
930   {
931     GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data",
932         ph.ats_string,
933         ph.total_iterations,
934         ph.N_peers_start,
935         ph.N_peers_end,
936         ph.N_address);
937     f_update = GNUNET_DISK_file_open (data_fn_update,
938         GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
939         GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
940     if (NULL == f_update)
941     {
942       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
943                   "Cannot open gnuplot file `%s'\n", data_fn_update);
944       GNUNET_free (data_fn_update);
945       if (NULL != f_full)
946         GNUNET_DISK_file_close (f_full);
947       GNUNET_free (data_fn_full);
948       return;
949     }
950
951     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
952                 "Using update data file `%s'\n",
953                 data_fn_update);
954
955     data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
956     if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data)))
957       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
958                   "Cannot write data to log file `%s'\n",
959                   data_fn_update);
960   }
961
962   for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer ++)
963   {
964     char * data_str;
965     char * data_tmp;
966     char * data_upd_str;
967     char * data_upd_tmp;
968     GNUNET_asprintf(&data_str, "%u;%u",c_peer, ph.N_address);
969     if (ph.measure_updates)
970       GNUNET_asprintf(&data_upd_str, "%u;%u",c_peer, ph.N_address);
971     for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration ++)
972     {
973       struct Result *cur_full_res;
974       struct Result *cur_upd_res;
975
976
977
978       //fprintf (stderr, "P: %u I: %u  == %p \n", c_peer, c_iteration, cur_res);
979       cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer];
980       if (c_peer == 0)
981         continue;
982       if (NULL == cur_full_res)
983         continue;
984
985       if (ph.measure_updates)
986       {
987         cur_upd_res = ph.iterations_results[c_iteration].update_results_array[c_peer];
988         data_upd_tmp = GNUNET_strdup (data_upd_str);
989         GNUNET_free (data_upd_str);
990         if (GNUNET_YES == cur_full_res->valid)
991         {
992           GNUNET_asprintf (&data_upd_str, "%s;%llu", data_upd_tmp,
993             (NULL == cur_upd_res) ? 0 : cur_upd_res->d_total_full.rel_value_us);
994         }
995         else
996         {
997             GNUNET_asprintf (&data_upd_str, "%s;", data_upd_tmp);
998         }
999         GNUNET_free (data_upd_tmp);
1000
1001       }
1002
1003       //fprintf (stderr, "P: %u I: %u: P %i  A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1004       //fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1005
1006       data_tmp = GNUNET_strdup (data_str);
1007       GNUNET_free (data_str);
1008       if (GNUNET_YES == cur_full_res->valid)
1009       {
1010           GNUNET_asprintf (&data_str, "%s;%llu", data_tmp,
1011               cur_full_res->d_total_full.rel_value_us);
1012       }
1013       else
1014       {
1015           GNUNET_asprintf (&data_str, "%s;", data_tmp);
1016       }
1017
1018       GNUNET_free (data_tmp);
1019     }
1020     data_tmp = GNUNET_strdup (data_str);
1021     GNUNET_free (data_str);
1022     GNUNET_asprintf (&data_str, "%s\n", data_tmp);
1023     GNUNET_free (data_tmp);
1024
1025     fprintf (stderr, "Result full solution: %s\n", data_str);
1026     if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data_str, strlen(data_str)))
1027       GNUNET_break (0);
1028     GNUNET_free (data_str);
1029
1030     if (ph.measure_updates)
1031     {
1032       data_upd_tmp = GNUNET_strdup (data_upd_str);
1033       GNUNET_free (data_upd_str);
1034       GNUNET_asprintf (&data_upd_str, "%s\n", data_upd_tmp);
1035       GNUNET_free (data_upd_tmp);
1036
1037       fprintf (stderr, "Result updated solution: `%s'\n", data_upd_str);
1038       if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data_upd_str, strlen(data_upd_str)))
1039         GNUNET_break (0);
1040       GNUNET_free (data_upd_str);
1041     }
1042   }
1043
1044   if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1045     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1046         data_fn_full);
1047   GNUNET_free_non_null (data_fn_full);
1048
1049   if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update)))
1050     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1051         data_fn_update);
1052   GNUNET_free_non_null (data_fn_update);
1053 }
1054
1055
1056 static int
1057 do_delete_address (void *cls,
1058                    const struct GNUNET_PeerIdentity *pid,
1059                    void *value)
1060 {
1061   struct ATS_Address *cur = value;
1062
1063   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1064              "Deleting addresses for peer %u\n",
1065              pid);
1066   GNUNET_assert (GNUNET_OK ==
1067                  GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1068                                                        pid,
1069                                                        cur));
1070   ph.sf->s_del (ph.sf->cls, cur);
1071   GNUNET_free_non_null (cur->atsi);
1072   GNUNET_free (cur);
1073   return GNUNET_OK;
1074 }
1075
1076
1077 /**
1078  * Run a performance iteration
1079  */
1080 static void
1081 perf_run_iteration (void)
1082 {
1083   int cp;
1084   int ca;
1085   int count_p = ph.N_peers_end;
1086   int count_a = ph.N_address;
1087   struct ATS_Address * cur_addr;
1088   uint32_t net;
1089
1090   ph.iterations_results[ph.current_iteration-1].results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *));
1091   if (ph.measure_updates)
1092     ph.iterations_results[ph.current_iteration-1].update_results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *));
1093   ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer));
1094   for (cp = 0; cp < count_p; cp++)
1095     perf_create_peer (cp);
1096   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1097       "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp);
1098
1099   for (cp = 0; cp < count_p; cp++)
1100   {
1101     fprintf (stderr,"%u..", cp);
1102     if (GNUNET_NO == ph.bulk_running)
1103     {
1104       ph.bulk_running = GNUNET_YES;
1105       ph.sf->s_bulk_start (ph.sf->cls);
1106     }
1107     ph.current_p = cp + 1;
1108     for (ca = 0; ca < count_a; ca++)
1109     {
1110       cur_addr = perf_create_address (cp, ca);
1111       /* Add address */
1112
1113       /* Random network selection */
1114       //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_NT_COUNT - 1);
1115       /* Random equally distributed network selection */
1116       net = 1 + (ca %  (GNUNET_NT_COUNT - 1));
1117       /* fprintf (stderr, "Network: %u `%s'\n",
1118        * mod_net , GNUNET_NT_to_string(mod_net)); */
1119
1120       cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information);
1121       cur_addr->atsi_count = 1;
1122       cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1123       cur_addr->atsi[0].value = htonl (net);
1124       ph.sf->s_add (ph.sf->cls, cur_addr, net);
1125
1126       ph.current_a = ca + 1;
1127       perf_address_initial_update (NULL, ph.addresses, cur_addr);
1128       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1129           "Adding address for peer %u address %u in network %s\n", cp, ca,
1130           GNUNET_NT_to_string(net));
1131     }
1132     /* Notify solver about request */
1133     ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
1134
1135     if (cp + 1 >= ph.N_peers_start)
1136     {
1137       /* Disable bulk to solve the problem */
1138       if (GNUNET_YES == ph.bulk_running)
1139       {
1140         ph.expecting_solution = GNUNET_YES;
1141         ph.bulk_running = GNUNET_NO;
1142         ph.sf->s_bulk_stop (ph.sf->cls);
1143       }
1144       else
1145         GNUNET_break (0);
1146
1147       /* Problem is solved by the solver here due to unlocking */
1148       ph.expecting_solution = GNUNET_NO;
1149
1150       /* Update the problem */
1151       if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1152       {
1153         /* Update */
1154         GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1155             "Updating problem with %u peers and %u addresses\n", cp + 1, ca);
1156
1157         ph.expecting_solution = GNUNET_YES;
1158         ph.performed_update = GNUNET_YES;
1159         if (GNUNET_NO == ph.bulk_running)
1160         {
1161           ph.bulk_running = GNUNET_YES;
1162           ph.sf->s_bulk_start (ph.sf->cls);
1163         }
1164         perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1165         ph.bulk_running = GNUNET_NO;
1166         ph.sf->s_bulk_stop (ph.sf->cls);
1167         /* Problem is solved by the solver here due to unlocking */
1168         ph.performed_update = GNUNET_NO;
1169         ph.expecting_solution = GNUNET_NO;
1170       }
1171       GNUNET_assert (GNUNET_NO == ph.bulk_running);
1172     }
1173   }
1174   fprintf (stderr,"\n");
1175   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1176       "Done, cleaning up addresses\n");
1177   if (GNUNET_NO == ph.bulk_running)
1178   {
1179     ph.sf->s_bulk_start (ph.sf->cls);
1180     ph.bulk_running = GNUNET_YES;
1181   }
1182
1183   for (cp = 0; cp < count_p; cp++)
1184   {
1185     GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
1186                                                 &ph.peers[cp].id,
1187                                                 &do_delete_address,
1188                                                 NULL);
1189   }
1190   if (GNUNET_NO == ph.bulk_running)
1191   {
1192     ph.sf->s_bulk_stop (ph.sf->cls);
1193     ph.bulk_running = GNUNET_NO;
1194   }
1195
1196   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1197       "Iteration done\n");
1198   GNUNET_free(ph.peers);
1199 }
1200
1201
1202 static void
1203 run (void *cls, char * const *args, const char *cfgfile,
1204     const struct GNUNET_CONFIGURATION_Handle *cfg)
1205 {
1206   GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1207   char *sep;
1208   char *src_filename = GNUNET_strdup (__FILE__);
1209   char *test_filename = cls;
1210   char *solver;
1211   char *plugin;
1212   struct GNUNET_CONFIGURATION_Handle *solver_cfg;
1213   unsigned long long quotas_in[GNUNET_NT_COUNT];
1214   unsigned long long quotas_out[GNUNET_NT_COUNT];
1215   int c;
1216   int c2;
1217
1218   /* Extract test name */
1219   if (NULL == (sep  = (strstr (src_filename,".c"))))
1220   {
1221     GNUNET_free (src_filename);
1222     GNUNET_break (0);
1223     ret = 1;
1224     return ;
1225   }
1226   sep[0] = '\0';
1227
1228   if (NULL != (sep = strstr (test_filename, ".exe")))
1229     sep[0] = '\0';
1230
1231   if (NULL == (solver = strstr (test_filename, src_filename)))
1232   {
1233     GNUNET_free (src_filename);
1234     GNUNET_break (0);
1235     ret = 1;
1236     return ;
1237   }
1238   solver += strlen (src_filename) +1;
1239
1240   if (0 == strcmp(solver, "proportional"))
1241   {
1242     ph.ats_string = "proportional";
1243   }
1244   else if (0 == strcmp(solver, "mlp"))
1245   {
1246     ph.ats_string = "mlp";
1247   }
1248   else if ((0 == strcmp(solver, "ril")))
1249   {
1250     ph.ats_string = "ril";
1251   }
1252   else
1253   {
1254     GNUNET_free (src_filename);
1255     GNUNET_break (0);
1256     ret = 1;
1257     return ;
1258   }
1259   GNUNET_free (src_filename);
1260
1261   /* Calculcate peers */
1262   if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1263   {
1264     ph.N_peers_start = DEFAULT_PEERS_START;
1265     ph.N_peers_end = DEFAULT_PEERS_END;
1266   }
1267   if (0 == ph.N_address)
1268     ph.N_address = DEFAULT_ADDRESSES;
1269
1270
1271   if (ph.N_peers_start != ph.N_peers_end)
1272     fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1273         ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations);
1274   else
1275     fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1276         ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations);
1277
1278   if (0 == ph.opt_update_percent)
1279     ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1280
1281   /* Load quotas */
1282   solver_cfg = GNUNET_CONFIGURATION_create();
1283   if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf"))))
1284   {
1285     GNUNET_break(0);
1286     end_now (1);
1287     return;
1288   }
1289   if (GNUNET_NT_COUNT != load_quotas (solver_cfg,
1290       quotas_out, quotas_in, GNUNET_NT_COUNT))
1291   {
1292     GNUNET_break(0);
1293     end_now (1);
1294     return;
1295   }
1296
1297   /* Create array of DLL to store results for iterations */
1298   ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.total_iterations);
1299
1300   /* Load solver */
1301   ph.env.cfg = solver_cfg;
1302   ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1303   ph.env.stats = ph.stat;
1304   ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1305   ph.env.addresses = ph.addresses;
1306   ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1307   ph.env.get_connectivity = &get_connectivity_cb;
1308   ph.env.get_preferences = &get_preferences_cb;
1309   ph.env.network_count = GNUNET_NT_COUNT;
1310   ph.env.info_cb = &solver_info_cb;
1311
1312   for (c = 0; c < GNUNET_NT_COUNT; c++)
1313   {
1314     ph.env.out_quota[c] = quotas_out[c];
1315     ph.env.in_quota[c] = quotas_in[c];
1316     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1317                 "Loading network quotas: `%s' %llu %llu \n",
1318                 GNUNET_NT_to_string (c),
1319                 ph.env.out_quota[c],
1320                 ph.env.in_quota[c]);
1321   }
1322   GAS_normalization_start ();
1323   GAS_preference_init ();
1324
1325   GNUNET_asprintf (&plugin,
1326                    "libgnunet_plugin_ats_%s",
1327                    ph.ats_string);
1328   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1329              _("Initializing solver `%s'\n"),
1330              ph.ats_string);
1331   if  (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
1332   {
1333     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1334                 _("Failed to initialize solver `%s'!\n"),
1335                 plugin);
1336     ret = 1;
1337     return;
1338   }
1339
1340   /* Do the benchmark */
1341   for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++)
1342   {
1343     fprintf (stderr,
1344              "Iteration %u of %u starting\n",
1345              ph.current_iteration,
1346              ph.total_iterations);
1347     perf_run_iteration ();
1348     evaluate (ph.current_iteration);
1349     fprintf (stderr,
1350              "Iteration %u of %u done\n",
1351              ph.current_iteration,
1352              ph.total_iterations);
1353   }
1354   if (ph.create_datafile)
1355     write_all_iterations ();
1356
1357   /* Unload solver*/
1358   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1359              _("Unloading solver `%s'\n"),
1360              ph.ats_string);
1361   GNUNET_PLUGIN_unload (plugin, ph.sf);
1362   ph.sf = NULL;
1363   GNUNET_free (plugin);
1364   for (c = 0; c < ph.total_iterations; c++ )
1365   {
1366     for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++ )
1367     {
1368       if (0 == c2)
1369         continue;
1370       if (ph.measure_updates)
1371         GNUNET_free_non_null (ph.iterations_results[c].update_results_array[c2]);
1372       GNUNET_free (ph.iterations_results[c].results_array[c2]);
1373     }
1374     if (ph.measure_updates)
1375       GNUNET_free (ph.iterations_results[c].update_results_array);
1376     GNUNET_free(ph.iterations_results[c].results_array);
1377   }
1378   GNUNET_free (ph.iterations_results);
1379
1380   GNUNET_CONFIGURATION_destroy (solver_cfg);
1381   GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1382 }
1383
1384
1385 /**
1386  * Main function of the benchmark
1387  *
1388  * @param argc argument count
1389  * @param argv argument values
1390  */
1391 int
1392 main (int argc, char *argv[])
1393 {
1394   /* extract command line arguments */
1395   ph.opt_update_percent = 0;
1396   ph.N_peers_start = 0;
1397   ph.N_peers_end = 0;
1398   ph.N_address = 0;
1399   ph.ats_string = NULL;
1400   ph.create_datafile = GNUNET_NO;
1401   ph.measure_updates = GNUNET_NO;
1402   ph.total_iterations = 1;
1403
1404   static struct GNUNET_GETOPT_CommandLineOption options[] = {
1405
1406       GNUNET_GETOPT_option_uint ('a',
1407                                      "addresses",
1408                                      gettext_noop ("addresses to use"),
1409                                      &ph.N_address),
1410
1411       GNUNET_GETOPT_option_uint ('s',
1412                                      "start",
1413                                      gettext_noop ("start with peer"),
1414                                      &ph.N_peers_start),
1415
1416       GNUNET_GETOPT_option_uint ('e',
1417                                      "end",
1418                                      gettext_noop ("end with peer"),
1419                                      &ph.N_peers_end),
1420
1421       GNUNET_GETOPT_option_uint ('i',
1422                                      "iterations",
1423                                      gettext_noop ("number of iterations used for averaging (default: 1)"),
1424                                      &ph.total_iterations),
1425
1426       GNUNET_GETOPT_option_uint ('p',
1427                                      "percentage",
1428                                      gettext_noop ("update a fix percentage of addresses"),
1429                                      &ph.opt_update_percent),
1430
1431       GNUNET_GETOPT_option_flag ('d',
1432                                     "data",
1433                                     gettext_noop ("create data file"),
1434                                     &ph.create_datafile),
1435
1436       GNUNET_GETOPT_option_flag ('u',
1437                                     "update",
1438                                     gettext_noop ("measure updates"),
1439                                     &ph.measure_updates),
1440
1441       GNUNET_GETOPT_OPTION_END
1442   };
1443
1444   GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1445   return ret;
1446 }
1447
1448 /* end of file perf_ats_solver.c */