aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-testbed-profiler.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-13 18:19:48 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-13 18:19:48 +0200
commit21c4b14e7e9a5f113b2c190b0223ca95074125b1 (patch)
treecb3105228f1ba52bea81c74caa642b26bc6c297e /src/testbed/gnunet-testbed-profiler.c
parentf5c99c11e752667d6c07d16568ae16a782b48e4c (diff)
downloadgnunet-21c4b14e7e9a5f113b2c190b0223ca95074125b1.tar.gz
gnunet-21c4b14e7e9a5f113b2c190b0223ca95074125b1.zip
Delete more subsystems not required after tng
Diffstat (limited to 'src/testbed/gnunet-testbed-profiler.c')
-rw-r--r--src/testbed/gnunet-testbed-profiler.c323
1 files changed, 0 insertions, 323 deletions
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
deleted file mode 100644
index 49d975119..000000000
--- a/src/testbed/gnunet-testbed-profiler.c
+++ /dev/null
@@ -1,323 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2008--2013 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/gnunet-testbed-profiler.c
23 * @brief Profiling driver for the testbed.
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_service.h"
30#include "testbed_api_hosts.h"
31
32/**
33 * Generic loggins shorthand
34 */
35#define LOG(kind, ...) \
36 GNUNET_log (kind, __VA_ARGS__)
37
38
39/**
40 * Handle to global configuration
41 */
42struct GNUNET_CONFIGURATION_Handle *cfg;
43
44/**
45 * Peer linking - topology operation
46 */
47struct GNUNET_TESTBED_Operation *topology_op;
48
49/**
50 * Name of the file with the hosts to run the test over (configuration option).
51 * It will be NULL if ENABLE_LL is set
52 */
53static char *hosts_file;
54
55/**
56 * Abort task identifier
57 */
58static struct GNUNET_SCHEDULER_Task *abort_task;
59
60/**
61 * Global event mask for all testbed events
62 */
63uint64_t event_mask;
64
65/**
66 * Number of peers to be started by the profiler
67 */
68static unsigned int num_peers;
69
70/**
71 * Number of timeout failures to tolerate
72 */
73static unsigned int num_cont_fails;
74
75/**
76 * Continuous failures during overlay connect operations
77 */
78static unsigned int cont_fails;
79
80/**
81 * Links which are successfully established
82 */
83static unsigned int established_links;
84
85/**
86 * Links which are not successfully established
87 */
88static unsigned int failed_links;
89
90/**
91 * Global testing status
92 */
93static int result;
94
95/**
96 * Are we running non interactively
97 */
98static int noninteractive;
99
100
101/**
102 * Shutdown nicely
103 *
104 * @param cls NULL
105 */
106static void
107do_shutdown (void *cls)
108{
109 if (NULL != abort_task)
110 {
111 GNUNET_SCHEDULER_cancel (abort_task);
112 abort_task = NULL;
113 }
114 if (NULL != cfg)
115 {
116 GNUNET_CONFIGURATION_destroy (cfg);
117 cfg = NULL;
118 }
119}
120
121
122/**
123 * abort task to run on test timed out
124 *
125 * @param cls NULL
126 */
127static void
128do_abort (void *cls)
129{
130 abort_task = NULL;
131 LOG (GNUNET_ERROR_TYPE_WARNING,
132 "Aborting\n");
133 result = GNUNET_SYSERR;
134 GNUNET_SCHEDULER_shutdown ();
135}
136
137
138/**
139 * Function to print summary about how many overlay links we have made and how
140 * many failed
141 */
142static void
143print_overlay_links_summary ()
144{
145 static int printed_already;
146
147 if (GNUNET_YES == printed_already)
148 return;
149 printed_already = GNUNET_YES;
150 printf ("%u links succeeded\n", established_links);
151 printf ("%u links failed due to timeouts\n", failed_links);
152}
153
154
155/**
156 * Controller event callback
157 *
158 * @param cls NULL
159 * @param event the controller event
160 */
161static void
162controller_event_cb (void *cls,
163 const struct GNUNET_TESTBED_EventInformation *event)
164{
165 switch (event->type)
166 {
167 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
168 /* Control reaches here when a peer linking operation fails */
169 if (NULL != event->details.operation_finished.emsg)
170 {
171 printf ("F");
172 fflush (stdout);
173 failed_links++;
174 if (++cont_fails > num_cont_fails)
175 {
176 printf ("\nAborting due to very high failure rate\n");
177 print_overlay_links_summary ();
178 GNUNET_SCHEDULER_shutdown ();
179 return;
180 }
181 }
182 break;
183
184 case GNUNET_TESTBED_ET_CONNECT:
185 {
186 if (0 != cont_fails)
187 cont_fails--;
188 if (0 == established_links)
189 printf ("Establishing links. Please wait\n");
190 printf (".");
191 fflush (stdout);
192 established_links++;
193 }
194 break;
195
196 default:
197 GNUNET_break (0);
198 }
199}
200
201
202/**
203 * Signature of a main function for a testcase.
204 *
205 * @param cls closure
206 * @param h the run handle
207 * @param num_peers number of peers in 'peers'
208 * @param peers handle to peers run in the testbed
209 * @param links_succeeded the number of overlay link connection attempts that
210 * succeeded
211 * @param links_failed the number of overlay link
212 */
213static void
214test_run (void *cls,
215 struct GNUNET_TESTBED_RunHandle *h,
216 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
217 unsigned int links_succeeded,
218 unsigned int links_failed)
219{
220 result = GNUNET_OK;
221 fprintf (stdout, "\n");
222 print_overlay_links_summary ();
223 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
224 if (noninteractive)
225 {
226 GNUNET_SCHEDULER_cancel (abort_task);
227 abort_task = NULL;
228 return;
229 }
230 fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
231 fflush (stdout);
232 (void) getc (stdin);
233 fprintf (stdout, "Shutting down. Please wait\n");
234 fflush (stdout);
235 GNUNET_SCHEDULER_shutdown ();
236}
237
238
239/**
240 * Main function that will be run by the scheduler.
241 *
242 * @param cls closure
243 * @param args remaining command-line arguments
244 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
245 * @param config configuration
246 */
247static void
248run (void *cls, char *const *args, const char *cfgfile,
249 const struct GNUNET_CONFIGURATION_Handle *config)
250{
251 if (0 == num_peers)
252 {
253 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Exiting as the number of peers is %u\n"),
254 num_peers);
255 return;
256 }
257 cfg = GNUNET_CONFIGURATION_dup (config);
258 event_mask = 0;
259 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
260 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
261 GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask,
262 &controller_event_cb, NULL,
263 &test_run, NULL);
264 abort_task =
265 GNUNET_SCHEDULER_add_shutdown (&do_abort,
266 NULL);
267}
268
269
270/**
271 * Main function.
272 *
273 * @return 0 on success
274 */
275int
276main (int argc, char *const *argv)
277{
278 struct GNUNET_GETOPT_CommandLineOption options[] = {
279 GNUNET_GETOPT_option_uint ('p',
280 "num-peers",
281 "COUNT",
282 gettext_noop ("create COUNT number of peers"),
283 &num_peers),
284 GNUNET_GETOPT_option_uint ('e',
285 "num-errors",
286 "COUNT",
287 gettext_noop (
288 "tolerate COUNT number of continuous timeout failures"),
289 &num_cont_fails),
290 GNUNET_GETOPT_option_flag ('n',
291 "non-interactive",
292 gettext_noop (
293 "run profiler in non-interactive mode where upon "
294 "testbed setup the profiler does not wait for a "
295 "keystroke but continues to run until a termination "
296 "signal is received"),
297 &noninteractive),
298 GNUNET_GETOPT_option_string ('H',
299 "hosts",
300 "FILENAME",
301 gettext_noop (
302 "name of the file with the login information for the testbed"),
303 &hosts_file),
304 GNUNET_GETOPT_OPTION_END
305 };
306 const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
307 int ret;
308
309 unsetenv ("XDG_DATA_HOME");
310 unsetenv ("XDG_CONFIG_HOME");
311 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
312 return 2;
313 result = GNUNET_SYSERR;
314 ret =
315 GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
316 options, &run, NULL);
317 GNUNET_free_nz ((void *) argv);
318 if (GNUNET_OK != ret)
319 return ret;
320 if (GNUNET_OK != result)
321 return 1;
322 return 0;
323}