Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / examples / msg / dht-chord / dht-chord.h
1 /* Copyright (c) 2016. The SimGrid Team.
2 * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef CHORD_CHORD_H_
8 #define CHORD_CHORD_H_
9 #include "simgrid/msg.h"
10 #include "simgrid/modelchecker.h"
11 #include <xbt/RngStream.h>
12 #include "src/mc/mc_replay.h" // FIXME: this is an internal header
13
14 #define COMM_SIZE 10
15 #define COMP_SIZE 0
16 #define MAILBOX_NAME_SIZE 10
17
18 /* Finger element. */
19 typedef struct s_finger {
20   int id;
21   char mailbox[MAILBOX_NAME_SIZE]; // string representation of the id
22 } s_finger_t;
23
24 /* Node data. */
25
26 typedef struct s_node {
27   int id;                                 // my id
28   char mailbox[MAILBOX_NAME_SIZE];        // my mailbox name (string representation of the id)
29   s_finger_t *fingers;                    // finger table, of size nb_bits (fingers[0] is my successor)
30   int pred_id;                            // predecessor id
31   char pred_mailbox[MAILBOX_NAME_SIZE];   // predecessor's mailbox name
32   int next_finger_to_fix;                 // index of the next finger to fix in fix_fingers()
33   msg_comm_t comm_receive;                // current communication to receive
34   double last_change_date;                // last time I changed a finger or my predecessor
35   RngStream stream;                       //RngStream for
36 } s_node_t;
37 typedef s_node_t *node_t;
38
39 /* Types of tasks exchanged between nodes. */
40 typedef enum {
41   TASK_FIND_SUCCESSOR,
42   TASK_FIND_SUCCESSOR_ANSWER,
43   TASK_GET_PREDECESSOR,
44   TASK_GET_PREDECESSOR_ANSWER,
45   TASK_NOTIFY,
46   TASK_SUCCESSOR_LEAVING,
47   TASK_PREDECESSOR_LEAVING,
48   TASK_PREDECESSOR_ALIVE,
49   TASK_PREDECESSOR_ALIVE_ANSWER
50 } e_task_type_t;
51
52 /* Data attached with the tasks sent and received */
53 typedef struct s_task_data {
54   e_task_type_t type;                     // type of task
55   int request_id;                         // id paramater (used by some types of tasks)
56   int request_finger;                     // finger parameter (used by some types of tasks)
57   int answer_id;                          // answer (used by some types of tasks)
58   char answer_to[MAILBOX_NAME_SIZE];      // mailbox to send an answer to (if any)
59   const char* issuer_host_name;           // used for logging
60 } s_task_data_t;
61 typedef s_task_data_t *task_data_t;
62
63 void create(node_t node);
64 int join(node_t node, int known_id);
65 void leave(node_t node);
66 int find_successor(node_t node, int id);
67 int remote_find_successor(node_t node, int ask_to_id, int id);
68 int remote_get_predecessor(node_t node, int ask_to_id);
69 int closest_preceding_node(node_t node, int id);
70 void stabilize(node_t node);
71 void notify(node_t node, int predecessor_candidate_id);
72 void remote_notify(int notify_to, int predecessor_candidate_id);
73 void fix_fingers(node_t node);
74 void check_predecessor(node_t node);
75 void random_lookup(node_t node);
76 void quit_notify(node_t node);
77
78 #endif