2 /* Copyright (c) 2010. The SimGrid Team.
3 * All rights reserved. */
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. */
11 #include "xbt/asserts.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chord,
13 "Messages specific for this msg example");
18 static int nb_bits = 16;
19 static int nb_keys = 0;
20 static int timeout = 50;
25 typedef struct finger {
28 } s_finger_t, *finger_t;
35 char* mailbox; // my usual mailbox name
36 s_finger_t *fingers; // finger table, of size nb_bits (fingers[0] is my successor)
37 int pred_id; // predecessor id
38 char* pred_mailbox; // predecessor's mailbox name
39 int next_finger_to_fix; // index of the next finger to fix in fix_fingers()
40 msg_comm_t comm_receive; // current communication to receive
41 xbt_dynar_t comms; // current communications being sent
42 double last_change_date; // last time I changed a finger or my predecessor
46 * Types of tasks exchanged between nodes.
50 TASK_FIND_SUCCESSOR_ANSWER,
52 TASK_GET_PREDECESSOR_ANSWER,
54 TASK_SUCCESSOR_LEAVING,
55 TASK_PREDECESSOR_LEAVING
59 * Data attached with the tasks sent and received
61 typedef struct task_data {
62 e_task_type_t type; // type of task
63 int request_id; // id paramater (used by some types of tasks)
64 int request_finger; // finger parameter (used by some types of tasks)
65 int answer_id; // answer (used by some types of tasks)
66 char* answer_to; // mailbox to send an answer to (or NULL)
67 const char* issuer_host_name; // used for logging
68 } s_task_data_t, *task_data_t;
73 static void chord_initialize(void);
74 static int normalize(int id);
75 static int is_in_interval(int id, int start, int end);
76 static char* get_mailbox(int host_id);
77 static void task_data_destroy(task_data_t task_data);
78 static void print_finger_table(node_t node);
79 static void set_finger(node_t node, int finger_index, int id);
80 static void set_predecessor(node_t node, int predecessor_id);
83 static int node(int argc, char *argv[]);
84 static void handle_task(node_t node, m_task_t task);
87 static void create(node_t node);
88 static int join(node_t node, int known_id);
89 static void leave(node_t node);
90 static int find_successor(node_t node, int id);
91 static int remote_find_successor(node_t node, int ask_to_id, int id);
92 static int remote_get_predecessor(node_t node, int ask_to_id);
93 static int closest_preceding_node(node_t node, int id);
94 static void stabilize(node_t node);
95 static void notify(node_t node, int predecessor_candidate_id);
96 static void remote_notify(node_t node, int notify_to, int predecessor_candidate_id);
97 static void fix_fingers(node_t node);
98 static void check_predecessor(node_t node);
99 static void quit_notify(node_t node, int to);
102 * \brief Global initialization of the Chord simulation.
104 static void chord_initialize(void)
106 // compute the powers of 2 once for all
107 powers2 = xbt_new(int, nb_bits);
110 for (i = 0; i < nb_bits; i++) {
115 DEBUG1("Sets nb_keys to %d", nb_keys);
119 * \brief Turns an id into an equivalent id in [0, nb_keys).
121 * \return the corresponding normalized id
123 static int normalize(int id)
129 // make sure id < nb_keys
136 * \brief Returns whether a id belongs to the interval [start, end].
138 * The parameters are noramlized to make sure they are between 0 and nb_keys - 1).
139 * 1 belongs to [62, 3]
140 * 1 does not belong to [3, 62]
141 * 63 belongs to [62, 3]
142 * 63 does not belong to [3, 62]
143 * 24 belongs to [21, 29]
144 * 24 does not belong to [29, 21]
146 * \param id id to check
147 * \param start lower bound
148 * \param end upper bound
149 * \return a non-zero value if id in in [start, end]
151 static int is_in_interval(int id, int start, int end)
154 start = normalize(start);
155 end = normalize(end);
157 // make sure end >= start and id >= start
170 * \brief Gets the mailbox name of a host given its chord id.
171 * \param node_id id of a node
172 * \return the name of its mailbox
174 static char* get_mailbox(int node_id)
176 return bprintf("mailbox%d", node_id);
180 * \brief Frees the memory used by some task data.
181 * \param task_data the task data to destroy
183 static void task_data_destroy(task_data_t task_data)
185 xbt_free(task_data->answer_to);
190 * \brief Displays the finger table of a node.
193 static void print_finger_table(node_t node)
195 if (XBT_LOG_ISENABLED(msg_chord, xbt_log_priority_verbose)) {
198 VERB0("My finger table:");
199 VERB0("Start | Succ ");
200 for (i = 0; i < nb_bits; i++) {
201 VERB2(" %3d | %3d ", (node->id + pow) % nb_keys, node->fingers[i].id);
204 VERB1("Predecessor: %d", node->pred_id);
209 * \brief Sets a finger of the current node.
210 * \param node the current node
211 * \param finger_index index of the finger to set (0 to nb_bits - 1)
212 * \param id the id to set for this finger
214 static void set_finger(node_t node, int finger_index, int id)
216 if (id != node->fingers[finger_index].id) {
217 node->fingers[finger_index].id = id;
218 xbt_free(node->fingers[finger_index].mailbox);
219 node->fingers[finger_index].mailbox = get_mailbox(id);
220 node->last_change_date = MSG_get_clock();
221 DEBUG2("My new finger #%d is %d", finger_index, id);
226 * \brief Sets the predecessor of the current node.
227 * \param node the current node
228 * \param id the id to predecessor, or -1 to unset the predecessor
230 static void set_predecessor(node_t node, int predecessor_id)
232 if (predecessor_id != node->pred_id) {
233 node->pred_id = predecessor_id;
234 xbt_free(node->pred_mailbox);
236 if (predecessor_id != -1) {
237 node->pred_mailbox = get_mailbox(predecessor_id);
239 node->last_change_date = MSG_get_clock();
241 DEBUG1("My new predecessor is %d", predecessor_id);
246 * \brief Node Function
249 * - the id of a guy I know in the system (except for the first node)
250 * - the time to sleep before I join (except for the first node)
252 int node(int argc, char *argv[])
254 double init_time = MSG_get_clock();
255 m_task_t task = NULL;
256 m_task_t task_received = NULL;
257 msg_comm_t comm_send = NULL;
260 int join_success = 0;
262 double next_stabilize_date = init_time + 10;
263 double next_fix_fingers_date = init_time + 10;
264 double next_check_predecessor_date = init_time + 10;
266 xbt_assert0(argc == 3 || argc == 5, "Wrong number of arguments for this node");
268 // initialize my node
270 node.id = atoi(argv[1]);
271 node.mailbox = get_mailbox(node.id);
272 node.next_finger_to_fix = 0;
273 node.comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
274 node.fingers = xbt_new0(s_finger_t, nb_bits);
275 node.last_change_date = MSG_get_clock();
277 for (i = 0; i < nb_bits; i++) {
278 set_finger(&node, i, node.id);
281 if (argc == 3) { // first ring
282 deadline = atof(argv[2]);
287 int known_id = atoi(argv[2]);
288 double sleep_time = atof(argv[3]);
289 deadline = atof(argv[4]);
291 // sleep before starting
292 DEBUG1("Let's sleep during %f", sleep_time);
293 MSG_process_sleep(sleep_time);
294 DEBUG0("Hey! Let's join the system.");
296 join_success = join(&node, known_id);
300 while (MSG_get_clock() < init_time + deadline
301 && MSG_get_clock() < node.last_change_date + 1000) {
303 if (node.comm_receive == NULL) {
304 task_received = NULL;
305 node.comm_receive = MSG_task_irecv(&task_received, node.mailbox);
306 // FIXME: do not make MSG_task_irecv() calls from several functions
309 if (!MSG_comm_test(node.comm_receive)) {
311 // no task was received: make some periodic calls
312 if (MSG_get_clock() >= next_stabilize_date) {
314 next_stabilize_date = MSG_get_clock() + 8;
316 else if (MSG_get_clock() >= next_fix_fingers_date) {
318 next_fix_fingers_date = MSG_get_clock() + 8;
320 else if (MSG_get_clock() >= next_check_predecessor_date) {
321 check_predecessor(&node);
322 next_check_predecessor_date = MSG_get_clock() + 8;
325 // nothing to do: sleep for a while
326 MSG_process_sleep(5);
330 // a transfer has occured
332 MSG_error_t status = MSG_comm_get_status(node.comm_receive);
334 if (status != MSG_OK) {
335 DEBUG0("Failed to receive a task. Nevermind.");
336 node.comm_receive = NULL;
339 // the task was successfully received
340 MSG_comm_destroy(node.comm_receive);
341 node.comm_receive = NULL;
342 handle_task(&node, task_received);
346 // see if some communications are finished
347 while ((index = MSG_comm_testany(node.comms)) != -1) {
348 comm_send = xbt_dynar_get_as(node.comms, index, msg_comm_t);
349 MSG_error_t status = MSG_comm_get_status(comm_send);
350 xbt_dynar_remove_at(node.comms, index, &comm_send);
351 DEBUG3("Communication %p is finished with status %d, dynar size is now %lu",
352 comm_send, status, xbt_dynar_length(node.comms));
353 MSG_comm_destroy(comm_send);
357 // clean unfinished comms sent
359 xbt_dynar_foreach(node.comms, cursor, comm_send) {
360 task = MSG_comm_get_task(comm_send);
361 MSG_task_cancel(task);
362 task_data_destroy(MSG_task_get_data(task));
363 MSG_task_destroy(task);
364 MSG_comm_destroy(comm_send);
365 // FIXME: the task is actually not destroyed because MSG thinks that the other side (whose process is dead) is still using it
372 // stop the simulation
373 xbt_dynar_free(&node.comms);
374 xbt_free(node.mailbox);
375 xbt_free(node.pred_mailbox);
376 for (i = 0; i < nb_bits - 1; i++) {
377 xbt_free(node.fingers[i].mailbox);
379 xbt_free(node.fingers);
384 * \brief This function is called when the current node receives a task.
385 * \param node the current node
386 * \param task the task to handle (don't touch it then:
387 * it will be destroyed, reused or forwarded)
389 static void handle_task(node_t node, m_task_t task) {
391 DEBUG1("Handling task %p", task);
392 msg_comm_t comm = NULL;
393 char* mailbox = NULL;
394 task_data_t task_data = (task_data_t) MSG_task_get_data(task);
395 e_task_type_t type = task_data->type;
399 case TASK_FIND_SUCCESSOR:
400 DEBUG2("Receiving a 'Find Successor' request from %s for id %d",
401 task_data->issuer_host_name, task_data->request_id);
402 // is my successor the successor?
403 if (is_in_interval(task_data->request_id, node->id + 1, node->fingers[0].id)) {
404 task_data->type = TASK_FIND_SUCCESSOR_ANSWER;
405 task_data->answer_id = node->fingers[0].id;
406 DEBUG3("Sending back a 'Find Successor Answer' to %s: the successor of %d is %d",
407 task_data->issuer_host_name,
408 task_data->request_id, task_data->answer_id);
409 comm = MSG_task_isend(task, task_data->answer_to);
410 xbt_dynar_push(node->comms, &comm);
413 // otherwise, forward the request to the closest preceding finger in my table
414 int closest = closest_preceding_node(node, task_data->request_id);
415 DEBUG2("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d",
416 task_data->request_id, closest);
417 mailbox = get_mailbox(closest);
418 comm = MSG_task_isend(task, mailbox);
419 xbt_dynar_push(node->comms, &comm);
424 case TASK_GET_PREDECESSOR:
425 DEBUG1("Receiving a 'Get Predecessor' request from %s", task_data->issuer_host_name);
426 task_data->type = TASK_GET_PREDECESSOR_ANSWER;
427 task_data->answer_id = node->pred_id;
428 DEBUG3("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d",
429 task_data->issuer_host_name,
430 task_data->answer_to, task_data->answer_id);
431 comm = MSG_task_isend(task, task_data->answer_to);
432 xbt_dynar_push(node->comms, &comm);
436 // someone is telling me that he may be my new predecessor
437 DEBUG1("Receiving a 'Notify' request from %s", task_data->issuer_host_name);
438 notify(node, task_data->request_id);
439 task_data_destroy(task_data);
440 MSG_task_destroy(task);
443 case TASK_PREDECESSOR_LEAVING:
444 // my predecessor is about to quit
445 DEBUG1("Receiving a 'Predecessor Leaving' message from %s", task_data->issuer_host_name);
446 // modify my predecessor
447 set_predecessor(node, task_data->request_id);
448 task_data_destroy(task_data);
449 MSG_task_destroy(task);
451 >> notify my new predecessor
452 >> send a notify_predecessors !!
456 case TASK_SUCCESSOR_LEAVING:
457 // my successor is about to quit
458 DEBUG1("Receiving a 'Successor Leaving' message from %s", task_data->issuer_host_name);
459 // modify my successor FIXME : this should be implicit ?
460 set_finger(node, 0, task_data->request_id);
461 task_data_destroy(task_data);
462 MSG_task_destroy(task);
464 >> notify my new successor
465 >> update my table & predecessors table */
468 case TASK_FIND_SUCCESSOR_ANSWER:
469 case TASK_GET_PREDECESSOR_ANSWER:
470 DEBUG2("Ignoring unexpected task of type %d (%p)", type, task);
476 * \brief Initializes the current node as the first one of the system.
477 * \param node the current node
479 static void create(node_t node)
481 DEBUG0("Create a new Chord ring...");
482 set_predecessor(node, -1); // -1 means that I have no predecessor
483 print_finger_table(node);
487 * \brief Makes the current node join the ring, knowing the id of a node
488 * already in the ring
489 * \param node the current node
490 * \param known_id id of a node already in the ring
491 * \return 1 if the join operation succeeded, 0 otherwise
493 static int join(node_t node, int known_id)
495 INFO2("Joining the ring with id %d, knowing node %d", node->id, known_id);
496 set_predecessor(node, -1); // no predecessor (yet)
498 int successor_id = remote_find_successor(node, known_id, node->id);
499 if (successor_id == -1) {
500 INFO0("Cannot join the ring.");
503 set_finger(node, 0, successor_id);
504 print_finger_table(node);
507 return successor_id != -1;
511 * \brief Makes the current node quit the system
512 * \param node the current node
514 static void leave(node_t node)
516 DEBUG0("Well Guys! I Think it's time for me to quit ;)");
517 quit_notify(node, 1); // notify to my successor ( >>> 1 );
518 quit_notify(node, -1); // notify my predecessor ( >>> -1);
523 * \brief Notifies the successor or the predecessor of the current node
525 * \param node the current node
526 * \param to 1 to notify the successor, -1 to notify the predecessor
527 * FIXME: notify both nodes with only one call
529 static void quit_notify(node_t node, int to)
532 task_data_t req_data = xbt_new0(s_task_data_t, 1);
533 req_data->request_id = node->id;
534 req_data->successor_id = node->fingers[0].id;
535 req_data->pred_id = node->pred_id;
536 req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
537 req_data->answer_to = NULL;
538 const char* task_name = NULL;
539 const char* to_mailbox = NULL;
540 if (to == 1) { // notify my successor
541 to_mailbox = node->fingers[0].mailbox;
542 INFO2("Telling my Successor %d about my departure via mailbox %s",
543 node->fingers[0].id, to_mailbox);
544 req_data->type = TASK_PREDECESSOR_LEAVING;
546 else if (to == -1) { // notify my predecessor
548 if (node->pred_id == -1) {
552 to_mailbox = node->pred_mailbox;
553 INFO2("Telling my Predecessor %d about my departure via mailbox %s",
554 node->pred_id, to_mailbox);
555 req_data->type = TASK_SUCCESSOR_LEAVING;
557 m_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
558 //char* mailbox = get_mailbox(to_mailbox);
559 msg_comm_t comm = MSG_task_isend(task, to_mailbox);
560 xbt_dynar_push(node->comms, &comm);
565 * \brief Makes the current node find the successor node of an id.
566 * \param node the current node
567 * \param id the id to find
568 * \return the id of the successor node, or -1 if the request failed
570 static int find_successor(node_t node, int id)
572 // is my successor the successor?
573 if (is_in_interval(id, node->id + 1, node->fingers[0].id)) {
574 return node->fingers[0].id;
577 // otherwise, ask the closest preceding finger in my table
578 int closest = closest_preceding_node(node, id);
579 return remote_find_successor(node, closest, id);
583 * \brief Asks another node the successor node of an id.
584 * \param node the current node
585 * \param ask_to the node to ask to
586 * \param id the id to find
587 * \return the id of the successor node, or -1 if the request failed
589 static int remote_find_successor(node_t node, int ask_to, int id)
593 char* mailbox = get_mailbox(ask_to);
594 task_data_t req_data = xbt_new0(s_task_data_t, 1);
595 req_data->type = TASK_FIND_SUCCESSOR;
596 req_data->request_id = id;
597 req_data->answer_to = xbt_strdup(node->mailbox);
598 req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
600 // send a "Find Successor" request to ask_to_id
601 m_task_t task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
602 DEBUG3("Sending a 'Find Successor' request (task %p) to %d for id %d", task_sent, ask_to, id);
603 MSG_error_t res = MSG_task_send_with_timeout(task_sent, mailbox, timeout);
606 DEBUG3("Failed to send the 'Find Successor' request (task %p) to %d for id %d",
607 task_sent, ask_to, id);
608 MSG_task_destroy(task_sent);
609 task_data_destroy(req_data);
613 // receive the answer
614 DEBUG3("Sent a 'Find Successor' request (task %p) to %d for key %d, waiting for the answer",
615 task_sent, ask_to, id);
618 if (node->comm_receive == NULL) {
619 m_task_t task_received = NULL;
620 node->comm_receive = MSG_task_irecv(&task_received, node->mailbox);
623 res = MSG_comm_wait(node->comm_receive, timeout);
626 DEBUG2("Failed to receive the answer to my 'Find Successor' request (task %p): %d",
629 //MSG_comm_destroy(node->comm_receive);
632 m_task_t task_received = MSG_comm_get_task(node->comm_receive);
633 DEBUG1("Received a task (%p)", task_received);
634 task_data_t ans_data = MSG_task_get_data(task_received);
636 if (task_received != task_sent) {
637 // this is not the expected answer
638 handle_task(node, task_received);
641 // this is our answer
642 DEBUG4("Received the answer to my 'Find Successor' request for id %d (task %p): the successor of key %d is %d",
643 ans_data->request_id, task_received, id, ans_data->answer_id);
644 successor = ans_data->answer_id;
646 MSG_task_destroy(task_received);
647 task_data_destroy(req_data);
650 node->comm_receive = NULL;
659 * \brief Asks another node its predecessor.
660 * \param node the current node
661 * \param ask_to the node to ask to
662 * \return the id of its predecessor node, or -1 if the request failed
663 * (or if the node does not know its predecessor)
665 static int remote_get_predecessor(node_t node, int ask_to)
667 int predecessor_id = -1;
669 char* mailbox = get_mailbox(ask_to);
670 task_data_t req_data = xbt_new0(s_task_data_t, 1);
671 req_data->type = TASK_GET_PREDECESSOR;
672 req_data->answer_to = xbt_strdup(node->mailbox);
673 req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
675 // send a "Get Predecessor" request to ask_to_id
676 DEBUG1("Sending a 'Get Predecessor' request to %d", ask_to);
677 m_task_t task_sent = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
678 MSG_error_t res = MSG_task_send_with_timeout(task_sent, mailbox, timeout);
681 DEBUG2("Failed to send the 'Get Predecessor' request (task %p) to %d",
683 MSG_task_destroy(task_sent);
684 task_data_destroy(req_data);
688 // receive the answer
689 DEBUG3("Sent 'Get Predecessor' request (task %p) to %d, waiting for the answer on my mailbox '%s'",
690 task_sent, ask_to, req_data->answer_to);
693 if (node->comm_receive == NULL) { // FIXME simplify this
694 m_task_t task_received = NULL;
695 node->comm_receive = MSG_task_irecv(&task_received, node->mailbox);
698 res = MSG_comm_wait(node->comm_receive, timeout);
701 DEBUG2("Failed to receive the answer to my 'Get Predecessor' request (task %p): %d",
704 //MSG_comm_destroy(node->comm_receive);
707 m_task_t task_received = MSG_comm_get_task(node->comm_receive);
708 task_data_t ans_data = MSG_task_get_data(task_received);
710 if (task_received != task_sent) {
711 handle_task(node, task_received);
714 DEBUG3("Received the answer to my 'Get Predecessor' request (task %p): the predecessor of node %d is %d",
715 task_received, ask_to, ans_data->answer_id);
716 predecessor_id = ans_data->answer_id;
718 MSG_task_destroy(task_received);
719 task_data_destroy(req_data);
722 node->comm_receive = NULL;
727 return predecessor_id;
731 * \brief Returns the closest preceding finger of an id
732 * with respect to the finger table of the current node.
733 * \param node the current node
734 * \param id the id to find
735 * \return the closest preceding finger of that id
737 int closest_preceding_node(node_t node, int id)
740 for (i = nb_bits - 1; i >= 0; i--) {
741 if (is_in_interval(node->fingers[i].id, node->id + 1, id - 1)) {
742 return node->fingers[i].id;
749 * \brief This function is called periodically. It checks the immediate
750 * successor of the current node.
751 * \param node the current node
753 static void stabilize(node_t node)
755 DEBUG0("Stabilizing node");
757 // get the predecessor of my immediate successor
759 int successor_id = node->fingers[0].id;
760 if (successor_id != node->id) {
761 candidate_id = remote_get_predecessor(node, successor_id);
764 candidate_id = node->pred_id;
767 // this node is a candidate to become my new successor
768 if (candidate_id != -1
769 && is_in_interval(candidate_id, node->id + 1, successor_id - 1)) {
770 set_finger(node, 0, candidate_id);
772 if (successor_id != node->id) {
773 remote_notify(node, successor_id, node->id);
778 * \brief Notifies the current node that its predecessor may have changed.
779 * \param node the current node
780 * \param candidate_id the possible new predecessor
782 static void notify(node_t node, int predecessor_candidate_id) {
784 if (node->pred_id == -1
785 || is_in_interval(predecessor_candidate_id, node->pred_id + 1, node->id - 1)) {
787 set_predecessor(node, predecessor_candidate_id);
788 print_finger_table(node);
791 DEBUG1("I don't have to change my predecessor to %d", predecessor_candidate_id);
796 * \brief Notifies a remote node that its predecessor may have changed.
797 * \param node the current node
798 * \param notify_id id of the node to notify
799 * \param candidate_id the possible new predecessor
801 static void remote_notify(node_t node, int notify_id, int predecessor_candidate_id) {
803 task_data_t req_data = xbt_new0(s_task_data_t, 1);
804 req_data->type = TASK_NOTIFY;
805 req_data->request_id = predecessor_candidate_id;
806 req_data->issuer_host_name = MSG_host_get_name(MSG_host_self());
807 req_data->answer_to = NULL;
809 // send a "Notify" request to notify_id
810 m_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
811 DEBUG2("Sending a 'Notify' request (task %p) to %d", task, notify_id);
812 char* mailbox = get_mailbox(notify_id);
813 msg_comm_t comm = MSG_task_isend(task, mailbox);
814 xbt_dynar_push(node->comms, &comm);
819 * \brief This function is called periodically.
820 * It refreshes the finger table of the current node.
821 * \param node the current node
823 static void fix_fingers(node_t node) {
825 DEBUG0("Fixing fingers");
826 int i = node->next_finger_to_fix;
827 int id = find_successor(node, node->id + powers2[i]);
830 if (id != node->fingers[i].id) {
831 set_finger(node, i, id);
832 print_finger_table(node);
834 node->next_finger_to_fix = (i + 1) % nb_bits;
839 * \brief This function is called periodically.
840 * It checks whether the predecessor has failed
841 * \param node the current node
843 static void check_predecessor(node_t node)
845 DEBUG0("Checking whether my predecessor is alive");
850 * \brief Main function.
852 int main(int argc, char *argv[])
855 printf("Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n", argv[0]);
856 printf("example: %s ../msg_platform.xml chord.xml\n", argv[0]);
860 MSG_global_init(&argc, argv);
862 char **options = &argv[1];
863 while (!strncmp(options[0], "-", 1)) {
865 int length = strlen("-nb_bits=");
866 if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) {
867 nb_bits = atoi(options[0] + length);
868 DEBUG1("Set nb_bits to %d", nb_bits);
872 length = strlen("-timeout=");
873 if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
874 timeout = atoi(options[0] + length);
875 DEBUG1("Set timeout to %d", timeout);
878 xbt_assert1(0, "Invalid chord option '%s'", options[0]);
884 const char* platform_file = options[0];
885 const char* application_file = options[1];
889 MSG_set_channel_number(0);
890 MSG_create_environment(platform_file);
892 MSG_function_register("node", node);
893 MSG_launch_application(application_file);
895 MSG_error_t res = MSG_main();
896 INFO1("Simulation time: %g", MSG_get_clock());