add testbed
[oweals/gnunet.git] / src / ats / perf_ats.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file ats/test_ats.c
22  * @brief ats benchmark: start peers and modify preferences, monitor change over time
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
29
30 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
31 #define TESTNAME_PREFIX "perf_ats_"
32
33
34 /**
35  * Shutdown task
36  */
37 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
38
39 static int result;
40 static char *solver;
41 static char *preference;
42
43 /**
44  * Shutdown nicely
45  *
46  * @param cls NULL
47  * @param tc the task context
48  */
49 static void
50 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51 {
52         shutdown_task = GNUNET_SCHEDULER_NO_TASK;
53
54         GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
55
56
57         GNUNET_SCHEDULER_shutdown();
58 }
59
60 /**
61  * Controller event callback
62  *
63  * @param cls NULL
64  * @param event the controller event
65  */
66 static void
67 controller_event_cb (void *cls,
68                      const struct GNUNET_TESTBED_EventInformation *event)
69 {
70
71 }
72
73 /**
74  * Signature of a main function for a testcase.
75  *
76  * @param cls closure
77  * @param num_peers number of peers in 'peers'
78  * @param peers_ handle to peers run in the testbed
79  * @param links_succeeded the number of overlay link connection attempts that
80  *          succeeded
81  * @param links_failed the number of overlay link connection attempts that
82  *          failed
83  */
84 static void
85 test_master (void *cls, unsigned int num_peers,
86              struct GNUNET_TESTBED_Peer **peers_,
87              unsigned int links_succeeded,
88              unsigned int links_failed)
89 {
90   GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking solver `%s' on preference `%s'\n"), solver, preference);
91
92   shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL);
93 }
94
95
96 int
97 main (int argc, char *argv[])
98 {
99         char *tmp;
100         char *tmp_sep;
101         char *test_name;
102         char *conf_name;
103
104   result = 1;
105
106   /* figure out testname */
107   tmp = strstr (argv[0], TESTNAME_PREFIX);
108   if (NULL == tmp)
109   {
110         fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
111         return GNUNET_SYSERR;
112   }
113   tmp += strlen(TESTNAME_PREFIX);
114   solver = GNUNET_strdup (tmp);
115   tmp_sep = strchr (solver, '_');
116   if (NULL == tmp_sep)
117   {
118         fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
119         GNUNET_free (solver);
120         return GNUNET_SYSERR;
121   }
122   tmp_sep[0] = '\0';
123   preference = GNUNET_strdup(tmp_sep + 1);
124
125   GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, preference);
126   GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, preference);
127
128   /* Start topology */
129   uint64_t event_mask;
130   result = GNUNET_SYSERR;
131   event_mask = 0;
132   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
133   event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
134   (void) GNUNET_TESTBED_test_run (test_name,
135                                   conf_name, 5,
136                                   event_mask, &controller_event_cb, NULL,
137                                   &test_master, NULL);
138
139   GNUNET_free (solver);
140   GNUNET_free (preference);
141   GNUNET_free (conf_name);
142   GNUNET_free (test_name);
143
144   return result;
145 }
146
147 /* end of file perf_ats.c */