Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3352280ad45d72c4ee4663984edb65d72c72406b
[simgrid.git] / examples / msg / chord / chord.c
1
2 /* Copyright (c) 2010. The SimGrid Team.
3  * All rights reserved.                                                     */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include <stdio.h>
9 #include "msg/msg.h"
10 #include "xbt/log.h"
11 #include "xbt/asserts.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chord,
13                              "Messages specific for this msg example");
14
15 #define NB_BITS 6
16 #define NB_KEYS 64
17
18 /**
19  * Finger element.
20  */
21 typedef struct finger {
22   int id;
23   char* mailbox;
24 } s_finger_t, *finger_t;
25
26 /**
27  * Node data.
28  */
29 typedef struct node {
30   int id;                                 // my id
31   char* mailbox;
32   s_finger_t fingers[NB_BITS];            // finger table (fingers[0] is my successor)
33   int pred_id;                            // predecessor id
34   char* pred_mailbox;
35   xbt_dynar_t comms;                      // current communications to finish
36 } s_node_t, *node_t;
37
38 /**
39  * Task data
40  */
41 typedef struct task_data {
42   int request_id;
43   int request_finger;
44   int answer_id;
45   const char* answer_to;
46   const char* issuer_host_name; // used for logging
47   int successor_id;                             // used when quitting
48   int pred_id;                                  // used when quitting
49 } s_task_data_t, *task_data_t;
50
51 // utility functions
52 static int normalize(int id);
53 static int is_in_interval(int id, int start, int end);
54 static char* get_mailbox(int host_id);
55 static void print_finger_table(node_t node);
56
57 // process functions
58 static int node(int argc, char *argv[]);
59
60 // initialization
61 static void initialize_first_node(node_t node);
62 static void initialize_finger_table(node_t data, int known_id);
63 static void join(node_t node, int known_id);
64 static void leave(node_t node);
65
66 // Chord core
67 static int find_successor(node_t node, int id);
68 static int remote_find_successor(node_t node, int ask_to_id, int id);
69 static int find_predecessor(node_t node, int id);
70 static int remote_find_predecessor(node_t node, int ask_to_id, int id);
71 static int closest_preceding_finger(node_t node, int id);
72 static int remote_closest_preceding_finger(int ask_to_id, int id);
73 static void notify_predecessors(node_t node);
74 static void remote_move_keys(node_t node, int take_from_id);
75 static void update_finger_table(node_t node, int candidate_id, int finger_index);
76 static void remote_update_finger_table(node_t node, int ask_to_id, int candidate_id, int finger_index);
77 static void notify(node_t node, int predecessor_candidate_id);
78 static void remote_notify(node_t node, int notify_to, int predecessor_candidate_id);
79 static void stabilize(node_t node);
80 static void quit_notify(node_t node, int to);
81
82 /**
83  * \brief Turns an id into an equivalent id in [0, NB_KEYS[
84  * \param id an id
85  * \return the corresponding normalized id
86  */
87 static int normalize(int id) {
88
89   // make sure id >= 0
90   while (id < 0) {
91     id += NB_KEYS;
92   }
93   // make sure id < NB_KEYS
94   id = id % NB_KEYS;
95
96   return id;
97 }
98
99 /**
100  * \brief Returns whether a id belongs to the interval [start, end].
101  *
102  * The parameters are noramlized to make sure they are between 0 and CHORD_NB_KEYS - 1).
103  * 1 belongs to [62, 3]
104  * 1 does not belong to [3, 62]
105  * 63 belongs to [62, 3]
106  * 63 does not belong to [3, 62]
107  * 24 belongs to [21, 29]
108  * 24 does not belong to [29, 21]
109  *
110  * \param id id to check
111  * \param start lower bound
112  * \param end upper bound
113  * \return a non-zero value if id in in [start, end]
114  */
115 static int is_in_interval(int id, int start, int end) {
116
117   id = normalize(id);
118   start = normalize(start);
119   end = normalize(end);
120
121   // make sure end >= start and id >= start
122   if (end < start) {
123     end += NB_KEYS;
124   }
125
126   if (id < start) {
127     id += NB_KEYS;
128   }
129
130   return id <= end;
131 }
132
133 /**
134  * \brief Gets the mailbox name of a host given its chord id.
135  * \param node_id id of a node
136  * \return the name of its mailbox
137  * FIXME: free the memory
138  */
139 static char* get_mailbox(int node_id) {
140
141   return bprintf("mailbox%d", node_id);
142 }
143
144 /**
145  * \brief Displays the finger table of a node.
146  * \param node a node
147  */
148 static void print_finger_table(node_t node) {
149
150   int i;
151   int pow = 1;
152   INFO0("My finger table:");
153   INFO0("Start | Succ ");
154   for (i = 0; i < NB_BITS; i++) {
155     INFO2(" %3d  | %3d ", (node->id + pow) % NB_KEYS, node->fingers[i].id);
156     pow = pow << 1;
157   }
158   INFO1("Predecessor: %d", node->pred_id);
159 }
160
161 /**
162  * \brief Node Function
163  * Arguments:
164  * - my id
165  * - the id of a guy I know in the system (except for the first node)
166  * - the time to sleep before I join (except for the first node)
167  */
168 int node(int argc, char *argv[])
169 {
170   double init_time = MSG_get_clock();
171   msg_comm_t comm = NULL;
172   int i;
173   char* mailbox;
174   double deadline;
175
176   xbt_assert0(argc == 3 || argc == 5, "Wrong number of arguments for this node");
177
178   // initialize my node
179   s_node_t node = {0};
180   node.id = atoi(argv[1]);
181   node.mailbox = get_mailbox(node.id);
182   node.comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
183
184
185   if (argc == 3) { // first ring
186     initialize_first_node(&node);
187     deadline = atof(argv[2]);
188   }
189   else {
190     int known_id = atoi(argv[2]);
191     double sleep_time = atof(argv[3]);
192     deadline = atof(argv[4]);
193
194     // sleep before starting
195     INFO1("Let's sleep >>%f", sleep_time);
196     MSG_process_sleep(sleep_time);
197     INFO0("Hey! Let's join the system.");
198
199     join(&node, known_id);
200   }
201
202   while ((MSG_get_clock( )- init_time) < deadline) {
203
204     unsigned int cursor;
205     comm = NULL;
206     xbt_dynar_foreach(node.comms, cursor, comm) {
207       if (MSG_comm_test(comm)) { // FIXME: try with MSG_comm_testany instead
208         xbt_dynar_cursor_rm(node.comms, &cursor);
209         MSG_comm_destroy(comm);
210       }
211     }
212
213     m_task_t task = NULL;
214     MSG_error_t res = MSG_task_receive_with_timeout(&task, node.mailbox,45); // FIXME >> find the right timeout !!
215
216     if(res == MSG_OK)                    // else check deadline condition and keep waiting for a task
217     {
218
219     // get data
220     const char* task_name = MSG_task_get_name(task);
221     task_data_t task_data = (task_data_t) MSG_task_get_data(task);
222
223     if (!strcmp(task_name, "Find Successor")) {
224       INFO2("Receiving a 'Find Successor' Request from %s for id %d", task_data->issuer_host_name, task_data->request_id);
225       // is my successor the successor?
226       if (is_in_interval(task_data->request_id, node.id + 1, node.fingers[0].id)) {
227         task_data->answer_id = node.fingers[0].id;
228         MSG_task_set_name(task, "Find Successor Answer");
229         INFO3("Sending back a 'Find Successor' Answer to %s: the successor of %d is %d", task_data->issuer_host_name, task_data->request_id, task_data->answer_id);
230         comm = MSG_task_isend(task, task_data->answer_to);
231         xbt_dynar_push(node.comms, &comm);
232       }
233       else {
234         // otherwise, forward the request to the closest preceding finger in my table
235         int closest = closest_preceding_finger(&node, task_data->request_id);
236         INFO2("Forwarding 'Find Successor' request for id %d to my closest preceding finger %d", task_data->request_id, closest);
237         mailbox = get_mailbox(closest);
238         comm = MSG_task_isend(task, mailbox);
239         xbt_dynar_push(node.comms, &comm);
240         xbt_free(mailbox);
241       }
242     }
243
244     else if (!strcmp(task_name, "Find Predecessor")) {
245       INFO2("Receiving a 'Find Predecessor' Request from %s for id %d", task_data->issuer_host_name, task_data->request_id);
246       // am I the predecessor?
247       if (is_in_interval(task_data->request_id, node.id + 1, node.fingers[0].id)) {
248         task_data->answer_id = node.id;
249         MSG_task_set_name(task, "Find Predecessor Answer");
250         INFO3("Sending back a 'Find Predecessor' Answer to %s: the predecessor of %d is %d", task_data->issuer_host_name, task_data->request_id, task_data->answer_id);
251         comm = MSG_task_isend(task, task_data->answer_to);
252         xbt_dynar_push(node.comms, &comm);
253       }
254       else {
255         // otherwise, forward the request to the closest preceding finger in my table
256         int closest = closest_preceding_finger(&node, task_data->request_id);
257         INFO2("Forwarding 'Find Predecessor' request for id %d to my closest preceding finger %d", task_data->request_id, closest);
258         mailbox = get_mailbox(closest);
259         comm = MSG_task_isend(task, mailbox);
260         xbt_dynar_push(node.comms, &comm);
261         xbt_free(mailbox);
262       }
263     }
264
265     else if (!strcmp(task_name, "Update Finger")) {
266       // someone is telling me that he may be my new finger
267       INFO1("Receiving an 'Update Finger' request from %s", task_data->issuer_host_name);
268       update_finger_table(&node, task_data->request_id, task_data->request_finger);
269     }
270     else if (!strcmp(task_name, "Notify")) {
271       // someone is telling me that he may be my new predecessor
272       INFO1("Receiving a 'Notify' request from %s", task_data->issuer_host_name);
273       notify(&node, task_data->request_id);
274     }
275     else if (!strcmp(task_name, "Predecessor Leaving")) {
276           // my predecessor is about quitting
277           INFO1("Receiving a 'quite notify' from %s", task_data->issuer_host_name);
278           // modify my predecessor
279           node.pred_id = task_data->pred_id;
280           node.pred_mailbox = get_mailbox(node.id);
281           /*TODO :
282           >> notify my new predecessor
283           >> send a notify_predecessors !!
284           */
285
286         }
287     else if (!strcmp(task_name, "Successor Leaving")) {
288           // my successor is about quitting
289           INFO1("Receiving a 'quite notify' from %s", task_data->issuer_host_name);
290           // modify my successor FIXME : this should be implicit ?
291           node.fingers[0].id = task_data->successor_id;
292           node.fingers[0].mailbox = get_mailbox(node.fingers[0].id);
293           /* TODO
294           >> notify my new successor
295           >> update my table & predecessors table */
296         }
297     }
298   }
299   // leave the ring and quit simulation
300   leave(&node);
301   xbt_dynar_free(&node.comms);
302   xbt_free(node.mailbox);
303   xbt_free(node.pred_mailbox);
304   for (i = 0; i < NB_BITS - 1; i++) {
305     xbt_free(node.fingers[i].mailbox);
306   }
307 }
308
309 /**
310  * \brief Initializes the current node as the first one of the system.
311  * \param node the current node
312  */
313 static void initialize_first_node(node_t node)
314 {
315   INFO0("Create a new Chord ring...");
316
317   // I am my own successor and predecessor
318   int i;
319   for (i = 0; i < NB_BITS; i++) {
320     node->fingers[i].id = node->id;
321     node->fingers[i].mailbox = xbt_strdup(node->mailbox);
322   }
323   node->pred_id = node->id;
324   node->pred_mailbox = node->mailbox;
325   print_finger_table(node);
326 }
327
328 /**
329  * \brief Makes the current node join the system, knowing the id of a node already in the system
330  * \param node the current node
331  * \param known_id id of a node already in the system
332  */
333 static void join(node_t node, int known_id)
334 {
335   initialize_finger_table(node, known_id); // determine my fingers, asking to known_id
336   remote_notify(node, node->fingers[0].id, node->id); // tell my successor that I'm his new predecessor
337   notify_predecessors(node); // tell others that I may have became their finger
338   remote_move_keys(node, node->fingers[0].id); // take some key-value pairs from my successor
339 }
340
341 /**
342  * \brief Makes the current node quit the system
343  * \param node the current node
344  */
345 static void leave(node_t node)
346 {
347         INFO0("Well Guys! I Think it's time for me to quit ;)");
348         quit_notify(node,1);            // notify to my successor ( >>> 1 );
349         quit_notify(node,-1);           // notify my predecessor  ( >>> -1);
350     // TODO ...
351 }
352 /*
353  * \brief Notify msg to tell my successor||predecessor about my departure
354  * \param node the current node
355  */
356 static void quit_notify(node_t node, int to)
357 {
358         task_data_t req_data = xbt_new0(s_task_data_t, 1);
359         req_data->request_id = node->id;
360         req_data->successor_id = node->fingers[0].id;
361         req_data->pred_id = node->pred_id;
362         req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
363         const char *task_name = NULL;
364         const char* to_mailbox;
365         if( to == 1)    // notify my successor
366         {
367                 to_mailbox = node->fingers[0].mailbox;
368             INFO1("Telling my Successor about my departure via mailbox %s", to_mailbox);
369                 task_name = "Predecessor Leaving";
370
371         }
372         else if(to == -1)    // notify my predecessor
373         {
374                 to_mailbox = node->pred_mailbox;
375             INFO1("Telling my Predecessor about my departure via mailbox %s",to_mailbox);
376                 task_name = "Predecessor Leaving";
377         }
378     m_task_t task = MSG_task_create(task_name, 1000, 5000, req_data);
379     //char* mailbox = get_mailbox(to_mailbox);
380         msg_comm_t comm = MSG_task_isend(task, to_mailbox);
381 }
382
383 /*
384  * \brief Initializes my finger table, knowing the id of a node already in the system.
385  * \param node the current node
386  * \param known_id id of a node already in the system
387  */
388 static void initialize_finger_table(node_t node, int known_id)
389 {
390   int my_id = node->id;
391   int i;
392   int pow = 1; // 2^i
393
394   INFO0("Initializing my finger table...");
395
396   // ask known_id who is my immediate successor
397   node->fingers[0].id = remote_find_successor(node, known_id, my_id + 1);
398   node->fingers[0].mailbox = get_mailbox(node->fingers[0].id);
399
400   // find all other fingers
401   for (i = 0; i < NB_BITS - 1; i++) {
402
403     pow = pow << 1; // equivalent to pow = pow * 2
404     if (is_in_interval(my_id + pow, my_id, node->fingers[i].id - 1)) {
405       // I already have the info for this finger
406       node->fingers[i + 1].id = node->fingers[i].id;
407     }
408     else {
409       // I don't have the info, ask the only guy I know
410       node->fingers[i + 1].id = remote_find_successor(node, known_id, my_id + pow);
411     }
412     node->fingers[i + 1].mailbox = get_mailbox(node->fingers[i + 1].id);
413   }
414
415   node->pred_id = find_predecessor(node, node->id);
416   node->pred_mailbox = get_mailbox(node->pred_id);
417
418   INFO0("Finger table initialized!");
419   print_finger_table(node);
420 }
421
422 /**
423  * \brief Notifies some nodes that the current node may have became their finger.
424  * \param node the current node, which has just joined the system
425  */
426 static void notify_predecessors(node_t node)
427 {
428   int i, pred_id;
429   int pow = 1;
430   for (i = 0; i < NB_BITS; i++) {
431     // find the closest node whose finger #i can be me
432     pred_id = find_predecessor(node, node->id - pow + 1); // note: no "+1" in the article!
433     if (pred_id != node->id) {
434       remote_update_finger_table(node, pred_id, node->id, i);
435     }
436     pow = pow << 1; // pow = pow * 2
437   }
438 }
439
440 /**
441  * \brief Tells the current node that a node may have became its new finger.
442  * \param node the current node
443  * \param candidate_id id of the node that may be a new finger of the current node
444  * \param finger_index index of the finger to update
445  */
446 static void update_finger_table(node_t node, int candidate_id, int finger_index)
447 {
448   int pow = 1;
449   int i;
450   for (i = 0; i < finger_index; i++) {
451     pow = pow << 1;
452   }
453
454   //  if (is_in_interval(candidate_id, node->id + pow, node->fingers[finger_index].id - 1)) {
455   if (is_in_interval(candidate_id, node->id, node->fingers[finger_index].id - 1)) {
456 //    INFO3("Candidate %d is between %d and %d!", candidate_id, node->id + pow, node->fingers[finger_index].id - 1);
457     // candidate_id is my new finger
458     xbt_free(node->fingers[finger_index].mailbox);
459     node->fingers[finger_index].id = candidate_id;
460     node->fingers[finger_index].mailbox = get_mailbox(candidate_id);
461     INFO2("My new finger #%d is %d", finger_index, candidate_id);
462     print_finger_table(node);
463
464     if (node->pred_id != node->id) { // FIXME: is this necessary?
465       // my predecessor may be concerned too
466       remote_update_finger_table(node, node->pred_id, candidate_id, finger_index);
467     }
468   }
469 }
470
471 /**
472  * \brief Tells a remote node that a node may have became its new finger.
473  * \param ask_to_id id of the remote node to update
474  * \param candidate_id id of the node that may be a new finger of the remote node
475  * \param finger_index index of the finger to update
476  */
477 static void remote_update_finger_table(node_t node, int ask_to_id, int candidate_id, int finger_index)
478 {
479   task_data_t req_data = xbt_new0(s_task_data_t, 1);
480   req_data->request_id = candidate_id;
481   req_data->request_finger = finger_index;
482   req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
483
484   // send a "Update Finger" request to ask_to_id
485   INFO3("Sending an 'Update Finger' request to %d: his finger #%d may be %d now", ask_to_id, finger_index, candidate_id);
486   m_task_t task = MSG_task_create("Update Finger", 1000, 5000, req_data);
487   char* mailbox = get_mailbox(ask_to_id);
488   msg_comm_t comm = MSG_task_isend(task, mailbox);
489   xbt_dynar_push(node->comms, &comm);
490   xbt_free(mailbox);
491 }
492
493 /**
494  * \brief Makes the current node find the successor node of an id.
495  * \param node the current node
496  * \param id the id to find
497  * \return the id of the successor node
498  */
499 static int find_successor(node_t node, int id)
500 {
501   // is my successor the successor?
502   if (is_in_interval(id, node->id + 1, node->fingers[0].id)) {
503     return node->fingers[0].id;
504   }
505
506   // otherwise, ask the closest preceding finger in my table
507   int closest = closest_preceding_finger(node, id);
508   return remote_find_successor(node, closest, id);
509 }
510
511 /**
512  * \brief Asks another node the successor node of an id.
513  * \param node the current node
514  * \param ask_to the node to ask to
515  * \param id the id to find
516  * \return the id of the successor node
517  */
518 static int remote_find_successor(node_t node, int ask_to, int id)
519 {
520   s_task_data_t req_data;
521   char* mailbox = bprintf("%s Find Successor", node->mailbox);
522   req_data.request_id = id;
523   req_data.answer_to = mailbox;
524   req_data.issuer_host_name = MSG_host_get_name(MSG_host_self());
525
526   // send a "Find Successor" request to ask_to_id
527   INFO2("Sending a 'Find Successor' request to %d for key %d", ask_to, id);
528   m_task_t task = MSG_task_create("Find Successor", 1000, 5000, &req_data);
529   MSG_task_send(task, get_mailbox(ask_to));
530
531   // receive the answer
532   task = NULL;
533   MSG_task_receive(&task, req_data.answer_to);
534   task_data_t ans_data;
535   ans_data = MSG_task_get_data(task);
536   int successor = ans_data->answer_id;
537   xbt_free(mailbox);
538   INFO2("Received the answer to my Find Successor request: the successor of key %d is %d", id, successor);
539
540   return successor;
541 }
542
543
544 /**
545  * \brief Makes the current node find the predecessor node of an id.
546  * \param node the current node
547  * \param id the id to find
548  * \return the id of the predecessor node
549  */
550 static int find_predecessor(node_t node, int id)
551 {
552   if (node->id == node->fingers[0].id) {
553     // I am the only node in the system
554     return node->id;
555   }
556
557   if (is_in_interval(id, node->id + 1, node->fingers[0].id)) {
558     return node->id;
559   }
560   int ask_to = closest_preceding_finger(node, id);
561   return remote_find_predecessor(node, ask_to, id);
562 }
563
564 /**
565  * \brief Asks another node the predecessor node of an id.
566  * \param node the current node
567  * \param ask_to the node to ask to
568  * \param id the id to find
569  * \return the id of the predecessor node
570  */
571 static int remote_find_predecessor(node_t node, int ask_to, int id)
572 {
573   s_task_data_t req_data;
574   char* mailbox = bprintf("%s Find Predecessor", node->mailbox);
575   req_data.request_id = id;
576   req_data.answer_to = mailbox;
577   req_data.issuer_host_name = MSG_host_get_name(MSG_host_self());
578
579   // send a "Find Predecessor" request to ask_to
580   INFO2("Sending a 'Find Predecessor' request to %d for key %d", ask_to, id);
581   m_task_t task = MSG_task_create("Find Predecessor", 1000, 5000, &req_data);
582   MSG_task_send(task, get_mailbox(ask_to));
583
584   // receive the answer
585   task = NULL;
586   MSG_task_receive(&task, req_data.answer_to);
587   task_data_t ans_data;
588   ans_data = MSG_task_get_data(task);
589   int predecessor = ans_data->answer_id;
590   xbt_free(mailbox);
591   INFO2("Received the answer to my 'Find Predecessor' request: the predecessor of key %d is %d", id, predecessor);
592
593   return predecessor;
594 }
595
596 /**
597  * \brief Returns the closest preceding finger of an id
598  * with respect to the finger table of the current node.
599  * \param node the current node
600  * \param id the id to find
601  * \return the closest preceding finger of that id
602  */
603 int closest_preceding_finger(node_t node, int id)
604 {
605   int i;
606   for (i = NB_BITS - 1; i >= 0; i--) {
607     if (is_in_interval(node->fingers[i].id, node->id + 1, id - 1)) {
608       return node->fingers[i].id;
609     }
610   }
611   return node->id;
612 }
613
614 /**
615  * \brief This function is called periodically. It checks the immediate
616  * successor of the current node.
617  * \param node the current node
618  */
619 static void stabilize(node_t node) {
620
621   int x = find_predecessor(node, node->fingers[0].id);
622   if (is_in_interval(x, node->id + 1, node->fingers[0].id)) {
623     xbt_free(node->fingers[0].mailbox);
624     node->fingers[0].id = x;
625     node->fingers[0].mailbox = get_mailbox(x);
626   }
627   remote_notify(node, node->fingers[0].id, node->id);
628 }
629
630 /**
631  * \brief Notifies the current node that its predecessor may have changed.
632  * \param node the current node
633  * \param candidate_id the possible new predecessor
634  */
635 static void notify(node_t node, int predecessor_candidate_id) {
636
637   if (node->pred_id == node->id
638     || is_in_interval(predecessor_candidate_id, node->pred_id, node->id)) {
639
640     node->pred_id = predecessor_candidate_id;
641     node->pred_mailbox = get_mailbox(predecessor_candidate_id);
642
643     INFO1("My new predecessor is %d", predecessor_candidate_id);
644     print_finger_table(node);
645   }
646   else {
647     INFO1("I don't have to change my predecessor to %d", predecessor_candidate_id);
648   }
649 }
650
651 /**
652  * \brief Notifies a remote node that its predecessor may have changed.
653  * \param node the current node
654  * \param notify_id id of the node to notify
655  * \param candidate_id the possible new predecessor
656  */
657 static void remote_notify(node_t node, int notify_id, int predecessor_candidate_id) {
658
659   task_data_t req_data = xbt_new0(s_task_data_t, 1);
660   req_data->request_id = predecessor_candidate_id;
661   req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
662
663   // send a "Notify" request to notify_id
664   INFO1("Sending a 'Notify' request to %d", notify_id);
665   m_task_t task = MSG_task_create("Notify", 1000, 5000, req_data);
666   char* mailbox = get_mailbox(notify_id);
667   msg_comm_t comm = MSG_task_isend(task, mailbox);
668   xbt_dynar_push(node->comms, &comm);
669   xbt_free(mailbox);
670 }
671
672 /**
673  * \brief Asks a node to take some of its keys.
674  * \param node the current node, which has just joined the system
675  * \param take_from_id id of a node who may have keys to give to the current node
676  */
677 static void remote_move_keys(node_t node, int take_from_id) {
678   // TODO
679 }
680
681 /**
682  * \brief Main function.
683  */
684 int main(int argc, char *argv[])
685 {
686   if (argc < 3) {
687     printf("Usage: %s platform_file deployment_file\n", argv[0]);
688     printf("example: %s ../msg_platform.xml chord.xml\n", argv[0]);
689     exit(1);
690   }
691
692   MSG_global_init(&argc, argv);
693
694   const char* platform_file = argv[1];
695   const char* application_file = argv[2];
696
697   /* MSG_config("workstation/model","KCCFLN05"); */
698   MSG_set_channel_number(0);
699   MSG_create_environment(platform_file);
700
701   MSG_function_register("node", node);
702   MSG_launch_application(application_file);
703
704   MSG_error_t res = MSG_main();
705   INFO1("Simulation time: %g", MSG_get_clock());
706
707   MSG_clean();
708
709   if (res == MSG_OK)
710     return 0;
711   else
712     return 1;
713 }