aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-testbed-profiler.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-10-12 15:44:53 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-10-12 15:44:53 +0000
commitd2cc065ef24dffcb7f09b471accef303935b4237 (patch)
tree0a2b68eb3a118189967ae7348a69d4e6c8cfe83a /src/testbed/gnunet-testbed-profiler.c
parent4f7742c31bcf64550dae6a14d6b6da54d6d57e59 (diff)
downloadgnunet-d2cc065ef24dffcb7f09b471accef303935b4237.tar.gz
gnunet-d2cc065ef24dffcb7f09b471accef303935b4237.zip
slave startup
Diffstat (limited to 'src/testbed/gnunet-testbed-profiler.c')
-rw-r--r--src/testbed/gnunet-testbed-profiler.c107
1 files changed, 90 insertions, 17 deletions
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
index 0191580c4..7e85f3ca2 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -63,6 +63,23 @@ struct DLLOperation
63 63
64 64
65/** 65/**
66 * Availanle states during profiling
67 */
68enum State
69{
70 /**
71 * Initial state
72 */
73 STATE_INIT = 0,
74
75 /**
76 * Starting slaves
77 */
78 STATE_SLAVES_STARTING
79};
80
81
82/**
66 * An array of hosts loaded from the hostkeys file 83 * An array of hosts loaded from the hostkeys file
67 */ 84 */
68static struct GNUNET_TESTBED_Host **hosts; 85static struct GNUNET_TESTBED_Host **hosts;
@@ -72,10 +89,10 @@ static struct GNUNET_TESTBED_Host **hosts;
72 */ 89 */
73static struct GNUNET_TESTBED_Peer **peers; 90static struct GNUNET_TESTBED_Peer **peers;
74 91
75/** 92/* /\** */
76 * Operation handle 93/* * Operation handle */
77 */ 94/* *\/ */
78static struct GNUNET_TESTBED_Operation *op; 95/* static struct GNUNET_TESTBED_Operation *op; */
79 96
80/** 97/**
81 * Host registration handle 98 * Host registration handle
@@ -98,6 +115,16 @@ struct GNUNET_TESTBED_Controller *mc;
98struct GNUNET_CONFIGURATION_Handle *cfg; 115struct GNUNET_CONFIGURATION_Handle *cfg;
99 116
100/** 117/**
118 * Head of the operations list
119 */
120struct DLLOperation *dll_op_head;
121
122/**
123 * Tail of the operations list
124 */
125struct DLLOperation *dll_op_tail;
126
127/**
101 * Abort task identifier 128 * Abort task identifier
102 */ 129 */
103static GNUNET_SCHEDULER_TaskIdentifier abort_task; 130static GNUNET_SCHEDULER_TaskIdentifier abort_task;
@@ -132,6 +159,11 @@ static unsigned int num_hosts;
132 */ 159 */
133static int result; 160static int result;
134 161
162/**
163 * current state of profiling
164 */
165enum State state;
166
135 167
136/** 168/**
137 * Shutdown nicely 169 * Shutdown nicely
@@ -142,6 +174,7 @@ static int result;
142static void 174static void
143do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 175do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
144{ 176{
177 struct DLLOperation *dll_op;
145 unsigned int nhost; 178 unsigned int nhost;
146 179
147 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 180 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
@@ -155,6 +188,16 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
155 if (NULL != hosts[nhost]) 188 if (NULL != hosts[nhost])
156 GNUNET_TESTBED_host_destroy (hosts[nhost]); 189 GNUNET_TESTBED_host_destroy (hosts[nhost]);
157 GNUNET_free_non_null (hosts); 190 GNUNET_free_non_null (hosts);
191 dll_op = dll_op_head;
192 while (NULL != dll_op)
193 {
194 GNUNET_TESTBED_operation_cancel (dll_op->op);
195 GNUNET_free_non_null (dll_op->cls);
196 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
197 GNUNET_free (dll_op);
198 }
199 if (NULL != mc)
200 GNUNET_TESTBED_controller_disconnect (mc);
158 if (NULL != mc_proc) 201 if (NULL != mc_proc)
159 GNUNET_TESTBED_controller_stop (mc_proc); 202 GNUNET_TESTBED_controller_stop (mc_proc);
160 if (NULL != cfg) 203 if (NULL != cfg)
@@ -189,19 +232,36 @@ static void
189controller_event_cb (void *cls, 232controller_event_cb (void *cls,
190 const struct GNUNET_TESTBED_EventInformation *event) 233 const struct GNUNET_TESTBED_EventInformation *event)
191{ 234{
192 235 struct DLLOperation *dll_op;
193 switch (event->type) 236 switch (state)
194 { 237 {
195 case GNUNET_TESTBED_ET_PEER_START: 238 case STATE_SLAVES_STARTING:
196 GNUNET_assert (NULL == peers[peer_id]); 239 switch (event->type)
197 GNUNET_assert (NULL != event->details.peer_start.peer); 240 {
198 peers[peer_id++] = event->details.peer_start.peer; 241 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
199 break; 242 {
200 case GNUNET_TESTBED_ET_PEER_STOP: 243 static unsigned int slaves_started;
201 GNUNET_assert (NULL != op); 244
202 GNUNET_TESTBED_operation_done (op); 245 dll_op = event->details.operation_finished.op_cls;
203 GNUNET_assert (peers[0] == event->details.peer_stop.peer); 246 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
204 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 247 if (NULL != event->details.operation_finished.emsg)
248 {
249 LOG (GNUNET_ERROR_TYPE_WARNING,
250 _("An operation has failed while starting slaves\n"));
251 GNUNET_SCHEDULER_cancel (abort_task);
252 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
253 return;
254 }
255 GNUNET_TESTBED_operation_done (dll_op->op);
256 GNUNET_free (dll_op);
257 /* Proceed to start peers */
258 if (++slaves_started == num_hosts - 1)
259 printf ("All slaves started successfully");
260 }
261 break;
262 default:
263 GNUNET_assert (0);
264 }
205 break; 265 break;
206 default: 266 default:
207 GNUNET_assert (0); 267 GNUNET_assert (0);
@@ -250,14 +310,27 @@ host_registration_completion (void *cls, const char *emsg)
250static void 310static void
251register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 311register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
252{ 312{
313 struct DLLOperation *dll_op;
253 static unsigned int reg_host; 314 static unsigned int reg_host;
315 unsigned int slave;
254 316
255 register_hosts_task = GNUNET_SCHEDULER_NO_TASK; 317 register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
256 if (reg_host == num_hosts - 1) 318 if (reg_host == num_hosts - 1)
257 { 319 {
258 LOG (GNUNET_ERROR_TYPE_DEBUG, 320 LOG (GNUNET_ERROR_TYPE_DEBUG,
259 "All hosts successfully registered\n"); 321 "All hosts successfully registered\n");
260 /* Start peer create task */ 322 /* Start slaves */
323 for (slave = 1; slave < num_hosts; slave++)
324 {
325 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
326 dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
327 mc,
328 hosts[slave],
329 NULL,
330 cfg,
331 GNUNET_YES);
332 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
333 }
261 return; 334 return;
262 } 335 }
263 reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host], 336 reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],