diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-22 20:52:27 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-22 20:52:27 +0000 |
commit | bd9f50c4923d523fdd3494a174b12a4926335149 (patch) | |
tree | 945e306f9f6d095c7bee5456ebc05b5d97aefbed /src/testbed | |
parent | a15908504806fee9b8225070d11fc2f01dbd2b05 (diff) | |
download | gnunet-bd9f50c4923d523fdd3494a174b12a4926335149.tar.gz gnunet-bd9f50c4923d523fdd3494a174b12a4926335149.zip |
clique topology
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/Makefile.am | 12 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_topology_clique.c | 169 | ||||
-rw-r--r-- | src/testbed/testbed_api_topology.c | 24 |
3 files changed, 203 insertions, 2 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index ec371e59d..e37d0ce11 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -87,7 +87,8 @@ check_PROGRAMS = \ | |||
87 | test_testbed_api_testbed_run \ | 87 | test_testbed_api_testbed_run \ |
88 | test_testbed_api_test \ | 88 | test_testbed_api_test \ |
89 | test_gnunet_helper_testbed \ | 89 | test_gnunet_helper_testbed \ |
90 | test_testbed_api_topology | 90 | test_testbed_api_topology \ |
91 | test_testbed_api_topology_clique | ||
91 | 92 | ||
92 | if ENABLE_TEST_RUN | 93 | if ENABLE_TEST_RUN |
93 | TESTS = \ | 94 | TESTS = \ |
@@ -100,7 +101,8 @@ if ENABLE_TEST_RUN | |||
100 | test_testbed_api_controllerlink \ | 101 | test_testbed_api_controllerlink \ |
101 | test_testbed_api_testbed_run \ | 102 | test_testbed_api_testbed_run \ |
102 | test_testbed_api_test \ | 103 | test_testbed_api_test \ |
103 | test_testbed_api_topology | 104 | test_testbed_api_topology \ |
105 | test_testbed_api_topology_clique | ||
104 | endif | 106 | endif |
105 | 107 | ||
106 | test_testbed_api_hosts_SOURCES = \ | 108 | test_testbed_api_hosts_SOURCES = \ |
@@ -161,6 +163,12 @@ test_testbed_api_topology_LDADD = \ | |||
161 | $(top_builddir)/src/util/libgnunetutil.la \ | 163 | $(top_builddir)/src/util/libgnunetutil.la \ |
162 | libgnunettestbed.la | 164 | libgnunettestbed.la |
163 | 165 | ||
166 | test_testbed_api_topology_clique_SOURCES = \ | ||
167 | test_testbed_api_topology_clique.c | ||
168 | test_testbed_api_topology_clique_LDADD = \ | ||
169 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
170 | libgnunettestbed.la | ||
171 | |||
164 | test_gnunet_helper_testbed_SOURCES = \ | 172 | test_gnunet_helper_testbed_SOURCES = \ |
165 | test_gnunet_helper_testbed.c | 173 | test_gnunet_helper_testbed.c |
166 | test_gnunet_helper_testbed_LDADD = \ | 174 | test_gnunet_helper_testbed_LDADD = \ |
diff --git a/src/testbed/test_testbed_api_topology_clique.c b/src/testbed/test_testbed_api_topology_clique.c new file mode 100644 index 000000000..f1330277b --- /dev/null +++ b/src/testbed/test_testbed_api_topology_clique.c | |||
@@ -0,0 +1,169 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2012 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 | /** | ||
22 | * @file src/testbed/test_testbed_api_topology.c | ||
23 | * @brief testing cases for testing high level testbed api helper functions | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | |||
31 | /** | ||
32 | * Number of peers we want to start | ||
33 | */ | ||
34 | #define NUM_PEERS 10 | ||
35 | |||
36 | /** | ||
37 | * Array of peers | ||
38 | */ | ||
39 | static struct GNUNET_TESTBED_Peer **peers; | ||
40 | |||
41 | /** | ||
42 | * Operation handle | ||
43 | */ | ||
44 | static struct GNUNET_TESTBED_Operation *op; | ||
45 | |||
46 | /** | ||
47 | * Shutdown task | ||
48 | */ | ||
49 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | ||
50 | |||
51 | /** | ||
52 | * Testing result | ||
53 | */ | ||
54 | static int result; | ||
55 | |||
56 | /** | ||
57 | * Counter for counting overlay connections | ||
58 | */ | ||
59 | static unsigned int overlay_connects; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Shutdown nicely | ||
64 | * | ||
65 | * @param cls NULL | ||
66 | * @param tc the task context | ||
67 | */ | ||
68 | static void | ||
69 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
70 | { | ||
71 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | ||
72 | if (NULL != op) | ||
73 | { | ||
74 | GNUNET_TESTBED_operation_done (op); | ||
75 | op = NULL; | ||
76 | } | ||
77 | GNUNET_SCHEDULER_shutdown (); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Controller event callback | ||
82 | * | ||
83 | * @param cls NULL | ||
84 | * @param event the controller event | ||
85 | */ | ||
86 | static void | ||
87 | controller_event_cb (void *cls, | ||
88 | const struct GNUNET_TESTBED_EventInformation *event) | ||
89 | { | ||
90 | switch (event->type) | ||
91 | { | ||
92 | case GNUNET_TESTBED_ET_CONNECT: | ||
93 | overlay_connects++; | ||
94 | if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) | ||
95 | { | ||
96 | result = GNUNET_OK; | ||
97 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
98 | } | ||
99 | break; | ||
100 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
101 | GNUNET_assert (NULL != event->details.operation_finished.emsg); | ||
102 | break; | ||
103 | default: | ||
104 | GNUNET_break (0); | ||
105 | if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && | ||
106 | (NULL != event->details.operation_finished.emsg)) | ||
107 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
108 | "An operation failed with error: %s\n", | ||
109 | event->details.operation_finished.emsg); | ||
110 | result = GNUNET_SYSERR; | ||
111 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
112 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Signature of a main function for a testcase. | ||
119 | * | ||
120 | * @param cls closure | ||
121 | * @param num_peers number of peers in 'peers' | ||
122 | * @param peers handle to peers run in the testbed | ||
123 | */ | ||
124 | static void | ||
125 | test_master (void *cls, unsigned int num_peers, | ||
126 | struct GNUNET_TESTBED_Peer **peers_) | ||
127 | { | ||
128 | unsigned int peer; | ||
129 | |||
130 | GNUNET_assert (NULL == cls); | ||
131 | GNUNET_assert (NUM_PEERS == num_peers); | ||
132 | GNUNET_assert (NULL != peers_); | ||
133 | for (peer = 0; peer < num_peers; peer++) | ||
134 | GNUNET_assert (NULL != peers_[peer]); | ||
135 | peers = peers_; | ||
136 | overlay_connects = 0; | ||
137 | op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, | ||
138 | GNUNET_TESTBED_TOPOLOGY_CLIQUE, | ||
139 | /* GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, */ | ||
140 | /* NUM_PEERS, */ | ||
141 | GNUNET_TESTBED_TOPOLOGY_OPTION_END); | ||
142 | GNUNET_assert (NULL != op); | ||
143 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
144 | (GNUNET_TIME_UNIT_SECONDS, 120), | ||
145 | do_shutdown, NULL); | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
150 | * Main function | ||
151 | */ | ||
152 | int | ||
153 | main (int argc, char **argv) | ||
154 | { | ||
155 | uint64_t event_mask; | ||
156 | |||
157 | result = GNUNET_SYSERR; | ||
158 | event_mask = 0; | ||
159 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
160 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
161 | GNUNET_TESTBED_test_run ("test_testbed_api_test", "test_testbed_api.conf", | ||
162 | NUM_PEERS, event_mask, &controller_event_cb, NULL, | ||
163 | &test_master, NULL); | ||
164 | if (GNUNET_OK != result) | ||
165 | return 1; | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | /* end of test_testbed_api_topology.c */ | ||
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 08d812e5e..2eb2d6dbd 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c | |||
@@ -298,6 +298,30 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
298 | tc->link_array[cnt].tc = tc; | 298 | tc->link_array[cnt].tc = tc; |
299 | } | 299 | } |
300 | break; | 300 | break; |
301 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: | ||
302 | tc->link_array_size = num_peers * (num_peers - 1); | ||
303 | tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * | ||
304 | tc->link_array_size); | ||
305 | { | ||
306 | unsigned int offset; | ||
307 | |||
308 | offset = 0; | ||
309 | for (cnt=0; cnt < num_peers; cnt++) | ||
310 | { | ||
311 | unsigned int neighbour; | ||
312 | |||
313 | for (neighbour=0; neighbour < num_peers; neighbour++) | ||
314 | { | ||
315 | if (neighbour == cnt) | ||
316 | continue; | ||
317 | tc->link_array[offset].A = cnt; | ||
318 | tc->link_array[offset].B = neighbour; | ||
319 | tc->link_array[offset].tc = tc; | ||
320 | offset++; | ||
321 | } | ||
322 | } | ||
323 | } | ||
324 | break; | ||
301 | default: | 325 | default: |
302 | GNUNET_break (0); | 326 | GNUNET_break (0); |
303 | return NULL; | 327 | return NULL; |