diff options
Diffstat (limited to 'src/testbed/testbed_api_cmd_netjail_stop_testbed.c')
-rw-r--r-- | src/testbed/testbed_api_cmd_netjail_stop_testbed.c | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/testbed/testbed_api_cmd_netjail_stop_testbed.c b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c new file mode 100644 index 000000000..9a9d489a7 --- /dev/null +++ b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 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 testing/testing_api_cmd_hello_world.c | ||
23 | * @brief Command to start the netjail peers. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_testbed_ng_service.h" | ||
29 | #include "testbed_api.h" | ||
30 | #include "testbed_api_hosts.h" | ||
31 | |||
32 | |||
33 | struct StopHelperState | ||
34 | { | ||
35 | |||
36 | const char *helper_start_label; | ||
37 | |||
38 | /** | ||
39 | * The process handle | ||
40 | */ | ||
41 | struct GNUNET_HELPER_Handle **helper; | ||
42 | |||
43 | char *local_m; | ||
44 | |||
45 | char *global_n; | ||
46 | }; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * | ||
51 | * | ||
52 | * @param cls closure | ||
53 | * @param cmd current CMD being cleaned up. | ||
54 | */ | ||
55 | static void | ||
56 | stop_testbed_cleanup (void *cls, | ||
57 | const struct GNUNET_TESTING_Command *cmd) | ||
58 | { | ||
59 | |||
60 | } | ||
61 | |||
62 | |||
63 | /** | ||
64 | * | ||
65 | * | ||
66 | * @param cls closure. | ||
67 | * @param[out] ret result | ||
68 | * @param trait name of the trait. | ||
69 | * @param index index number of the object to offer. | ||
70 | * @return #GNUNET_OK on success. | ||
71 | */ | ||
72 | static int | ||
73 | stop_testbed_traits (void *cls, | ||
74 | const void **ret, | ||
75 | const char *trait, | ||
76 | unsigned int index) | ||
77 | { | ||
78 | return GNUNET_OK; | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Run the "hello world" CMD. | ||
84 | * | ||
85 | * @param cls closure. | ||
86 | * @param cmd CMD being run. | ||
87 | * @param is interpreter state. | ||
88 | */ | ||
89 | static void | ||
90 | stop_testbed_run (void *cls, | ||
91 | const struct GNUNET_TESTING_Command *cmd, | ||
92 | struct GNUNET_TESTING_Interpreter *is) | ||
93 | { | ||
94 | struct StopHelperState *shs = cls; | ||
95 | struct GNUNET_HELPER_Handle **helper; | ||
96 | const struct GNUNET_TESTING_Command *start_helper_cmd; | ||
97 | |||
98 | start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command ( | ||
99 | shs->helper_start_label); | ||
100 | GNUNET_TESTBED_get_trait_helper_handles (start_helper_cmd, | ||
101 | &helper); | ||
102 | |||
103 | for (int i = 1; i <= atoi (shs->global_n); i++) { | ||
104 | for (int j = 1; j <= atoi (shs->local_m); j++) | ||
105 | { | ||
106 | GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1], | ||
107 | GNUNET_YES); | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Create command. | ||
115 | * | ||
116 | * @param label name for command. | ||
117 | * @param binaryname to exec. | ||
118 | * @return command. | ||
119 | */ | ||
120 | struct GNUNET_TESTING_Command | ||
121 | GNUNET_TESTBED_cmd_stop_testbed (const char *label, | ||
122 | const char *helper_start_label, | ||
123 | char *local_m, | ||
124 | char *global_n | ||
125 | ) | ||
126 | { | ||
127 | struct StopHelperState *shs; | ||
128 | |||
129 | shs = GNUNET_new (struct StopHelperState); | ||
130 | shs->helper_start_label = helper_start_label; | ||
131 | shs->local_m = local_m; | ||
132 | shs->global_n = global_n; | ||
133 | |||
134 | struct GNUNET_TESTING_Command cmd = { | ||
135 | .cls = shs, | ||
136 | .label = label, | ||
137 | .run = &stop_testbed_run, | ||
138 | .cleanup = &stop_testbed_cleanup, | ||
139 | .traits = &stop_testbed_traits | ||
140 | }; | ||
141 | |||
142 | return cmd; | ||
143 | } | ||