XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg_kademlia_node);
-/**
- * Initialize a node answer object.
- */
+/** Initialize a node answer object. */
answer_t answer_init(unsigned int destination_id)
{
answer_t answer = xbt_new(s_answer_t, 1);
return answer;
}
-/**
- * Destroys a node answer object.
- */
+/** Destroys a node answer object. */
void answer_free(answer_t answer)
{
unsigned int i;
xbt_free(answer);
}
-/**
- * @brief Prints a answer_t, for debugging purposes
- */
+/** @brief Prints a answer_t, for debugging purposes */
void answer_print(answer_t answer)
{
unsigned int cpt;
node_contact_t contact;
XBT_INFO("Searching %08x, size %d", answer->destination_id, answer->size);
xbt_dynar_foreach(answer->nodes, cpt, contact) {
- XBT_INFO("Node %08x: %08x is at distance %d", cpt, contact->id,
- contact->distance);
+ XBT_INFO("Node %08x: %08x is at distance %d", cpt, contact->id, contact->distance);
}
}
-/**
- * @brief Merge two answer_t together, only keeping the best nodes
+/** @brief Merge two answer_t together, only keeping the best nodes
* @param destination the destination in which the nodes will be put
* @param source the source of the nodes to add
*/
return nb_added;
}
-/**
- * Helper to sort answer_t objects
- */
+/** Helper to sort answer_t objects */
static int _answer_sort_function(const void *e1, const void *e2)
{
node_contact_t c1 = *(void **) e1;
return 1;
}
-/**
- * Sorts a answer_t, by node distance.
+/** @brief Sorts a answer_t, by node distance.
* @param answer the answer to sort
* @param destination_id the id of the guy we are trying to find
*/
xbt_dynar_sort(answer->nodes, &_answer_sort_function);
}
-/**
- * Trims a answer_t, in order for it to have a size of less or equal
- * to "bucket_size"
+/** @brief Trims a answer_t, in order for it to have a size of less or equal to "bucket_size"
* @param answer the answer_t to trim
*/
void answer_trim(answer_t answer)
answer->size--;
node_contact_free(value);
}
- xbt_assert(xbt_dynar_length(answer->nodes) == answer->size,
- "Wrong size for the answer");
+ xbt_assert(xbt_dynar_length(answer->nodes) == answer->size, "Wrong size for the answer");
}
-/**
- * Adds the content of a bucket unsigned into a answer object.
+/** @brief Adds the content of a bucket unsigned into a answer object.
* @param bucket the bucket we have to had unsigned into
* @param answer the answer object we're going to put the data in
* @param destination_id the id of the guy we are trying to find.
}
}
-/**
- * Returns if the id supplied is in the answer.
+/** @brief Returns if the id supplied is in the answer.
* @param id : id we're looking for
*/
unsigned int answer_contains(answer_t answer, unsigned int id)
{
- unsigned int i = 0, size = xbt_dynar_length(answer->nodes);
+ unsigned int i = 0;
node_contact_t contact;
- for (i = 0; i < size; i++) {
- contact = xbt_dynar_get_as(answer->nodes, i, node_contact_t);
+ xbt_dynar_foreach(answer->nodes, i, contact){
if (id == contact->id) {
return 1;
}
return 0;
}
-/**
- * Returns if the destination we are trying to find is found
+/** @brief Returns if the destination we are trying to find is found
* @param answer the answer
* @return if the destination is found.
*/
if (xbt_dynar_length(answer->nodes) < 1) {
return 0;
}
- node_contact_t contact_tail =
- xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
+ node_contact_t contact_tail = xbt_dynar_get_as(answer->nodes, 0, node_contact_t);
return contact_tail->distance == 0;
}
-/* Copyright (c) 2012, 2014. The SimGrid Team.
+/* Copyright (c) 2012, 2014, 2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#define _KADEMLIA_EXAMPLES_ANSWER_H_
#include <xbt/dynar.h>
#include "routing_table.h"
-/*
- * Node query anwser. contains the elements closest
- * to the id given.
- */
+
+/* Node query anwser. contains the elements closest to the id given. */
typedef struct s_node_answer {
unsigned int destination_id;
xbt_dynar_t nodes; //Dynar of node_contact_t
all_ids = [0]
sys.stdout.write("<?xml version='1.0'?>\n"
-"<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"
-"<platform version=\"3\">\n"
-" <process host=\"c-0.me\" function=\"node\"><argument value=\"0000000000000000000000000000000000000000\"/><argument value=\"%d\"/></process>\n" % end_date)
+"<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n"
+"<platform version=\"4\">\n <process host=\"node-0.acme.org\" function=\"node\">\n"
+" <argument value=\"0\"/>\n <argument value=\"%d\"/>\n </process>\n" % end_date)
for i in range(1, nb_nodes):
ok = False
ok = not my_id in all_ids
known_id = all_ids[random.randint(0, len(all_ids) - 1)]
start_date = i * 10
- line = " <process host=\"c-%d.me\" function=\"node\"><argument value=\"%s\" /><argument value=\"%s\" /><argument value=\"%d\" /></process>\n" % (i, my_id, known_id,end_date)
+ line = " <process host=\"node-%d.acme.org\" function=\"node\">\n <argument value=\"%s\"/>"\
+ "\n <argument value=\"%s\"/>\n <argument value=\"%d\"/>\n </process>\n" % (i, my_id, known_id,end_date)
sys.stdout.write(line)
all_ids.append(my_id)
-/* Copyright (c) 2012, 2014-2015. The SimGrid Team.
+/* Copyright (c) 2012, 2014-2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* <b>kademlia/kademlia.c: Kademlia protocol</b>
* Implements the Kademlia protocol, using 32 bits identifiers.
*/
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia,
- "Messages specific for this msg example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia, "Messages specific for this msg example");
extern long unsigned int smx_total_comms;
-/**
- * Main loop for the process
- */
+/* Main loop for the process */
static void main_loop(node_t node, double deadline)
{
double next_lookup_time = MSG_get_clock() + random_lookup_interval;
node->receive_comm = NULL;
if (status == MSG_OK) {
- xbt_assert((node->task_received != NULL),
- "We received an incorrect task");
+ xbt_assert((node->task_received != NULL), "We received an incorrect task");
handle_task(node, node->task_received);
} else {
- xbt_assert((MSG_comm_get_task(node->receive_comm) == NULL),
- "Comm failed but received a task.");
+ xbt_assert((MSG_comm_get_task(node->receive_comm) == NULL), "Comm failed but received a task.");
XBT_DEBUG("Nevermind, the communication has failed.");
}
}
}
//Cleanup the receiving communication.
if (node->receive_comm != NULL) {
- if (MSG_comm_test(node->receive_comm)
- && MSG_comm_get_status(node->receive_comm) == MSG_OK) {
+ if (MSG_comm_test(node->receive_comm) && MSG_comm_get_status(node->receive_comm) == MSG_OK) {
task_free(MSG_comm_get_task(node->receive_comm));
}
MSG_comm_destroy(node->receive_comm);
}
}
-/**
- * \brief Node function
- * Arguments :
- * - my node ID
- * - the ID of the person I know in the system (or not)
- * - Time before I leave the system because I'm bored
+/** @brief Node function
+ * @param my node ID
+ * @param the ID of the person I know in the system (or not)
+ * @param Time before I leave the system because I'm bored
*/
static int node(int argc, char *argv[])
{
XBT_INFO("I couldn't join the network :(");
}
XBT_DEBUG("I'm leaving the network");
- XBT_INFO("%d/%d FIND_NODE have succeeded", node->find_node_success,
- node->find_node_success + node->find_node_failed);
+ XBT_INFO("%d/%d FIND_NODE have succeeded", node->find_node_success, node->find_node_success + node->find_node_failed);
node_free(node);
return 0;
}
/**
- * Tries to join the network
+ * @brief Tries to join the network
* @param node node data
* @param id_known id of the node I know in the network.
*/
node_list = data->answer;
xbt_dynar_foreach(node_list->nodes, i, contact) {
node_routing_table_update(node, contact->id);
- //ping(node,contact->id);
}
task_free(node->task_received);
} else {
} while (answer_got == 0 && trial < max_join_trials);
/* Second step: Send a FIND_NODE to a a random node in buckets */
unsigned int bucket_id = routing_table_find_bucket(node->table, id_known)->id;
- for (i = 0;
- ((bucket_id - i) > 0 || (bucket_id + i) <= identifier_size)
- && i < JOIN_BUCKETS_QUERIES; i++) {
+ for (i = 0; ((bucket_id - i) > 0 || (bucket_id + i) <= identifier_size) && i < JOIN_BUCKETS_QUERIES; i++) {
if (bucket_id - i > 0) {
unsigned int id_in_bucket = get_id_in_prefix(node->id, bucket_id - i);
find_node(node, id_in_bucket, 0);
return answer_got;
}
-/**
- * Send a request to find a node in the node routing table.
- * @brief node our node data
- * @brief id_to_find the id of the node we are trying to find
+/** @brief Send a request to find a node in the node routing table.
+ * @param node our node data
+ * @param id_to_find the id of the node we are trying to find
*/
-unsigned int find_node(node_t node, unsigned int id_to_find,
- unsigned int count_in_stats)
+unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_in_stats)
{
-
unsigned int i = 0;
unsigned int queries, answers;
unsigned int destination_found = 0;
msg_error_t status;
- /* Ask the nodes on our list if they have information about
- * the node we are trying to find */
-
+ /* Ask the nodes on our list if they have information about the node we are trying to find */
do {
answers = 0;
queries = send_find_node_to_best(node, node_list);
do {
if (node->receive_comm == NULL) {
node->task_received = NULL;
- node->receive_comm =
- MSG_task_irecv(&node->task_received, node->mailbox);
+ node->receive_comm = MSG_task_irecv(&node->task_received, node->mailbox);
}
if (node->receive_comm) {
if (MSG_comm_test(node->receive_comm)) {
xbt_assert((data != NULL), "No data in the task");
//Check if what we have received is what we are looking for.
- if (data->type == TASK_FIND_NODE_ANSWER
- && data->answer->destination_id == id_to_find) {
+ if (data->type == TASK_FIND_NODE_ANSWER && data->answer->destination_id == id_to_find) {
//Handle the answer
node_routing_table_update(node, data->sender_id);
node_contact_t contact;
nodes_added = answer_merge(node_list, data->answer);
XBT_DEBUG("Received an answer from %s (%s) with %ld nodes on it",
- data->answer_to, data->issuer_host_name,
- xbt_dynar_length(data->answer->nodes));
+ data->answer_to, data->issuer_host_name, xbt_dynar_length(data->answer->nodes));
task_free(node->task_received);
} else {
}
} while (MSG_get_clock() < timeout && answers < queries);
destination_found = answer_destination_found(node_list);
- } while (!destination_found && (nodes_added > 0 || answers == 0)
- && MSG_get_clock() < global_timeout && steps < MAX_STEPS);
+ } while (!destination_found && (nodes_added > 0 || answers == 0) && MSG_get_clock() < global_timeout
+ && steps < MAX_STEPS);
if (destination_found) {
if (count_in_stats)
node->find_node_success++;
return destination_found;
}
-/**
- * Pings a node in the system to see if it is online.
+/** @brief Pings a node in the system to see if it is online.
* @param node Our node data
* @param id_to_ping the id of a node we want to see if it is online.
* @return if the ping succeded or not.
unsigned int destination_found = 0;
double timeout = MSG_get_clock() + ping_timeout;
- msg_task_t ping_task =
- task_new_ping(node->id, node->mailbox,
- MSG_host_get_name(MSG_host_self()));
+ msg_task_t ping_task = task_new_ping(node->id, node->mailbox, MSG_host_get_name(MSG_host_self()));
msg_task_t task_received = NULL;
XBT_VERB("PING %08x", id_to_ping);
do {
task_received = NULL;
msg_error_t status =
- MSG_task_receive_with_timeout(&task_received, node->mailbox,
- ping_timeout);
+ MSG_task_receive_with_timeout(&task_received, node->mailbox, ping_timeout);
if (status == MSG_OK) {
xbt_assert((task_received != NULL), "Invalid task received");
//Checking if it's what we are waiting for or not.
return 1;
}
-/**
- * Does a pseudo-random lookup for someone in the system
+/** @brief Does a pseudo-random lookup for someone in the system
* @param node caller node data
*/
void random_lookup(node_t node)
find_node(node, id_to_look, 1);
}
-/**
- * @brief Send a "FIND_NODE" to a node
+/** @brief Send a "FIND_NODE" to a node
* @param node sender node data
* @param id node we are querying
* @param destination node we are trying to find.
/* Gets the mailbox to send to */
get_node_mailbox(id, mailbox);
/* Build the task */
- msg_task_t task =
- task_new_find_node(node->id, destination, node->mailbox,
- MSG_host_get_name(MSG_host_self()));
+ msg_task_t task = task_new_find_node(node->id, destination, node->mailbox, MSG_host_get_name(MSG_host_self()));
/* Send the task */
xbt_assert((task != NULL), "Trying to send a NULL task.");
MSG_task_dsend(task, mailbox, task_free_v);
unsigned int i = 0, j = 0;
unsigned int destination = node_list->destination_id;
node_contact_t node_to_query;
- while (j < kademlia_alpha && i < node_list->size) { /* We need to have at most "kademlia_alpha" requets each time, according to the protocol */
+ while (j < kademlia_alpha && i < node_list->size) {
+ /* We need to have at most "kademlia_alpha" requests each time, according to the protocol */
/* Gets the node we want to send the query to */
node_to_query = xbt_dynar_get_as(node_list->nodes, i, node_contact_t);
if (node_to_query->id != node->id) { /* No need to query ourselves */
return i;
}
-/**
- * \brief Handles an incomming received task
- */
+/** @brief Handles an incoming received task */
void handle_task(node_t node, msg_task_t task)
{
task_data_t data = MSG_task_get_data(task);
handle_ping(node, data);
break;
default:
-
break;
}
task_free(task);
}
-/**
- * \brief Handles the answer to an incomming "find_node" task
- */
+/** @brief Handles the answer to an incoming "find_node" task */
void handle_find_node(node_t node, task_data_t data)
{
XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x",
//Building the answer to the request
answer_t answer = node_find_closest(node, data->destination_id);
//Building the task to send
- msg_task_t task =
- task_new_find_node_answer(node->id, data->destination_id, answer,
- node->mailbox,
- MSG_host_get_name(MSG_host_self()));
+ msg_task_t task = task_new_find_node_answer(node->id, data->destination_id, answer, node->mailbox,
+ MSG_host_get_name(MSG_host_self()));
//Sending the task
MSG_task_dsend(task, data->answer_to, task_free_v);
}
-/**
- * \brief handles the answer to a ping
- */
+/** @brief handles the answer to a ping */
void handle_ping(node_t node, task_data_t data)
{
- XBT_VERB("Received a PING request from %s (%s)", data->answer_to,
- data->issuer_host_name);
+ XBT_VERB("Received a PING request from %s (%s)", data->answer_to, data->issuer_host_name);
//Building the answer to the request
- msg_task_t task =
- task_new_ping_answer(node->id, data->answer_to,
- MSG_host_get_name(MSG_host_self()));
+ msg_task_t task = task_new_ping_answer(node->id, data->answer_to, MSG_host_get_name(MSG_host_self()));
MSG_task_dsend(task, data->answer_to, task_free_v);
}
-/**
- * \brief Main function
- */
+/** @brief Main function */
int main(int argc, char *argv[])
{
-
MSG_init(&argc, argv);
/* Check the arguments */
- xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
- "\tExample: %s msg_platform.xml msg_deployment.xml\n",
- argv[0], argv[0]);
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n\tExample: %s msg_platform.xml msg_deployment.xml\n",
+ argv[0], argv[0]);
const char *platform_file = argv[1];
const char *deployment_file = argv[2];
MSG_create_environment(platform_file);
-
MSG_function_register("node", node);
MSG_launch_application(deployment_file);
-/* Copyright (c) 2012, 2014. The SimGrid Team.
+/* Copyright (c) 2012, 2014, 2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
//core kademlia functions
unsigned int join(node_t node, unsigned int id_known);
-unsigned int find_node(node_t node, unsigned int id_to_find,
- unsigned int count_in_stats);
+unsigned int find_node(node_t node, unsigned int id_to_find, unsigned int count_in_stats);
unsigned int ping(node_t node, unsigned int id_to_ping);
void random_lookup(node_t node);
void handle_find_node(node_t node, task_data_t data);
void handle_ping(node_t node, task_data_t data);
-
#endif /* _MSG_EXAMPLES_KADEMLIA_H */
p Testing the Kademlia implementation with MSG
! output sort 19
-$ $SG_TEST_EXENV ${bindir:=.}/kademlia ${srcdir:=.}/../../platforms/platform.xml ${srcdir:=.}/kademlia.xml "--log=root.fmt:[%10.6r]%e(%02i:%P@%h)%e%m%n"
-> [ 0.000000] ( 1:node@Jacquelin) Hi, I'm going to create the network with id 00000000
-> [ 0.000000] ( 2:node@Boivin) Hi, I'm going to join the network with id 00000001
-> [ 0.000000] ( 3:node@Jean_Yves) Hi, I'm going to join the network with id 00000003
-> [ 0.000000] ( 4:node@TeX) Hi, I'm going to join the network with id 00000007
-> [ 0.000000] ( 5:node@Geoff) Hi, I'm going to join the network with id 0000000f
-> [ 0.000000] ( 6:node@Disney) Hi, I'm going to join the network with id 0000001f
-> [ 0.000000] ( 7:node@iRMX) Hi, I'm going to join the network with id 0000003f
-> [ 0.000000] ( 8:node@McGee) Hi, I'm going to join the network with id 0000007f
-> [ 0.000000] ( 9:node@Gatien) Hi, I'm going to join the network with id 000000ff
-> [ 0.000000] (10:node@Laroche) Hi, I'm going to join the network with id 000001ff
-> [ 0.000000] (11:node@Tanguay) Hi, I'm going to join the network with id 000003ff
-> [ 0.000000] (12:node@Morin) Hi, I'm going to join the network with id 000007ff
-> [ 0.000000] (13:node@Ethernet) Hi, I'm going to join the network with id 00000fff
-> [900.000000] ( 0:maestro@) Messages created: 1277
-> [900.000000] ( 0:maestro@) Simulated time: 900
-> [900.000000] ( 1:node@Jacquelin) 8/8 FIND_NODE have succeeded
-> [900.000000] ( 2:node@Boivin) 7/7 FIND_NODE have succeeded
-> [900.000000] ( 3:node@Jean_Yves) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 4:node@TeX) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 5:node@Geoff) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 6:node@Disney) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 7:node@iRMX) 6/6 FIND_NODE have succeeded
-> [900.000000] ( 8:node@McGee) 7/7 FIND_NODE have succeeded
-> [900.000000] ( 9:node@Gatien) 6/6 FIND_NODE have succeeded
-> [900.000000] (10:node@Laroche) 6/6 FIND_NODE have succeeded
-> [900.000000] (11:node@Tanguay) 6/6 FIND_NODE have succeeded
-> [900.000000] (12:node@Morin) 7/7 FIND_NODE have succeeded
-> [900.000000] (13:node@Ethernet) 7/7 FIND_NODE have succeeded
+$ $SG_TEST_EXENV ${bindir:=.}/kademlia ${srcdir:=.}/../../platforms/cluster.xml ${srcdir:=.}/kademlia.xml "--log=root.fmt:[%10.6r]%e(%02i:%P@%h)%e%m%n"
+> [ 0.000000] ( 1:node@node-0.acme.org) Hi, I'm going to create the network with id 00000000
+> [ 0.000000] ( 2:node@node-1.acme.org) Hi, I'm going to join the network with id 00000001
+> [ 0.000000] ( 3:node@node-2.acme.org) Hi, I'm going to join the network with id 00000003
+> [ 0.000000] ( 4:node@node-3.acme.org) Hi, I'm going to join the network with id 00000007
+> [ 0.000000] ( 5:node@node-4.acme.org) Hi, I'm going to join the network with id 0000000f
+> [ 0.000000] ( 6:node@node-5.acme.org) Hi, I'm going to join the network with id 0000001f
+> [ 0.000000] ( 7:node@node-6.acme.org) Hi, I'm going to join the network with id 0000003f
+> [ 0.000000] ( 8:node@node-7.acme.org) Hi, I'm going to join the network with id 0000007f
+> [ 0.000000] ( 9:node@node-8.acme.org) Hi, I'm going to join the network with id 000000ff
+> [ 0.000000] (10:node@node-9.acme.org) Hi, I'm going to join the network with id 000001ff
+> [ 0.000000] (11:node@node-10.acme.org) Hi, I'm going to join the network with id 000003ff
+> [ 0.000000] (12:node@node-11.acme.org) Hi, I'm going to join the network with id 000007ff
+> [ 0.000000] (13:node@node-12.acme.org) Hi, I'm going to join the network with id 00000fff
+> [780.000000] ( 7:node@node-6.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 9:node@node-8.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 3:node@node-2.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 2:node@node-1.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] (11:node@node-10.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 1:node@node-0.acme.org) 7/7 FIND_NODE have succeeded
+> [780.000000] ( 5:node@node-4.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] (13:node@node-12.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 8:node@node-7.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 6:node@node-5.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] (10:node@node-9.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] (12:node@node-11.acme.org) 6/6 FIND_NODE have succeeded
+> [780.000000] ( 4:node@node-3.acme.org) 5/5 FIND_NODE have succeeded
+> [780.000000] ( 0:maestro@) Messages created: 1179
+> [780.000000] ( 0:maestro@) Simulated time: 780
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
<platform version="4">
- <process host="Jacquelin" function="node">
+ <process host="node-0.acme.org" function="node">
<argument value="0x0000"/> <!-- my id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Boivin" function="node">
+ <process host="node-1.acme.org" function="node">
<argument value="0x0001"/> <!-- my id -->
<argument value="0"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Jean_Yves" function="node">
+ <process host="node-2.acme.org" function="node">
<argument value="0x0003"/> <!-- my id -->
<argument value="0x0001"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="TeX" function="node">
+ <process host="node-3.acme.org" function="node">
<argument value="0x0007"/> <!-- my id -->
<argument value="0x0003"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Geoff" function="node">
+ <process host="node-4.acme.org" function="node">
<argument value="0x000f"/> <!-- my id -->
<argument value="0x0007"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Disney" function="node">
+ <process host="node-5.acme.org" function="node">
<argument value="0x001f"/> <!-- my id -->
<argument value="0x000f"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="iRMX" function="node">
+ <process host="node-6.acme.org" function="node">
<argument value="0x003f"/> <!-- my id -->
<argument value="0x001f"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="McGee" function="node">
+ <process host="node-7.acme.org" function="node">
<argument value="0x007f"/> <!-- my id -->
<argument value="0x003f"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Gatien" function="node">
+ <process host="node-8.acme.org" function="node">
<argument value="0x00ff"/> <!-- my id -->
<argument value="0x007f"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Laroche" function="node">
+ <process host="node-9.acme.org" function="node">
<argument value="0x01ff"/> <!-- my id -->
<argument value="0x00ff"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Tanguay" function="node">
+ <process host="node-10.acme.org" function="node">
<argument value="0x03ff"/> <!-- my id -->
<argument value="0x01ff"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Morin" function="node">
+ <process host="node-11.acme.org" function="node">
<argument value="0x07ff"/> <!-- my id -->
<argument value="0x03ff"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
- <process host="Ethernet" function="node">
+ <process host="node-12.acme.org" function="node">
<argument value="0x0fff"/> <!-- my id -->
<argument value="0x0000"/> <!-- known id -->
- <argument value ="900"/> <!-- deadline -->
+ <argument value ="780"/> <!-- deadline -->
</process>
</platform>
-/* Copyright (c) 2010, 2012-2015. The SimGrid Team.
+/* Copyright (c) 2010, 2012-2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "simgrid/msg.h"
#include "xbt/log.h"
#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_node,
- "Messages specific for this msg example");
-/**
- * \brief Initialization of a node
- * \param node_id the id of the node
- * \return the node created
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_node, "Messages specific for this msg example");
+
+/** @brief Initialization of a node
+ * @param node_id the id of the node
+ * @return the node created
*/
node_t node_init(unsigned int node_id)
{
return node;
}
-/*
- * \brief Node destructor
- */
+/* @brief Node destructor */
void node_free(node_t node)
{
routing_table_free(node->table);
xbt_free(node);
}
-/**
- * @brief Updates/Puts the node id unsigned into our routing table
+/** @brief Updates/Puts the node id unsigned into our routing table
* @param node Our node data
* @param id The id of the node we need to add unsigned into our routing table
*/
unsigned int id_pos = bucket_find_id(bucket, id);
if (id_pos == -1) {
- /* We check if the bucket is full or not. If it is, we evict
- * old offline elements */
+ /* We check if the bucket is full or not. If it is, we evict old offline elements */
if (xbt_dynar_length(bucket->nodes) < bucket_size) {
//TODO: this is not really very efficient. Maybe we should use something else than dynars ?
xbt_dynar_unshift(bucket->nodes, &id);
XBT_VERB("I'm adding to my routing table %08x", id);
} else {
- /* TODO: we need to evict the old elements: that's why this function is in "node" instead of "routing table". This is not implemented yet. */
+ /* TODO: we need to evict the old elements: that's why this function is in "node" instead of "routing table".
+ * This is not implemented yet. */
}
} else {
//We push to the front of the dynar the element.
- unsigned int element =
- xbt_dynar_get_as(bucket->nodes, id_pos, unsigned int);
+ unsigned int element = xbt_dynar_get_as(bucket->nodes, id_pos, unsigned int);
xbt_dynar_remove_at(bucket->nodes, id_pos, NULL);
xbt_dynar_unshift(bucket->nodes, &element);
XBT_VERB("I'm updating %08x", element);
}
}
-/**
- * Finds the closest nodes to the node given.
+/** @brief Finds the closest nodes to the node given.
* @param node : our node
* @param destination_id : the id of the guy we are trying to find
*/
/* We find the corresponding bucket for the id */
bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
int bucket_id = bucket->id;
- xbt_assert((bucket_id <= identifier_size),
- "Bucket found has a wrong identifier");
+ xbt_assert((bucket_id <= identifier_size), "Bucket found has a wrong identifier");
/* So, we copy the contents of the bucket unsigned into our result dynar */
answer_add_bucket(bucket, answer);
- /* However, if we don't have enough elements in our bucket, we NEED to
- include at least
- * "bucket_size" elements (if, of course, we know at least "bucket_size" elements. So we're going to look unsigned into the other buckets.
+ /* However, if we don't have enough elements in our bucket, we NEED to include at least "bucket_size" elements
+ * (if, of course, we know at least "bucket_size" elements. So we're going to look unsigned into the other buckets.
*/
- for (i = 1;
- answer->size < bucket_size && ((bucket_id - i > 0)
- || (bucket_id + i < identifier_size));
- i++) {
+ for (i = 1; answer->size < bucket_size && ((bucket_id - i > 0) || (bucket_id + i < identifier_size)); i++) {
/* We check the previous buckets */
if (bucket_id - i >= 0) {
bucket_t bucket_p = &node->table->buckets[bucket_id - i];
return answer;
}
-/**
- * Returns an identifier which is in a specific bucket of a routing table
- * @brief id id of the routing table owner
- * @brief prefix id of the bucket where we want that identifier to be
+/**@brief Returns an identifier which is in a specific bucket of a routing table
+ * @param id id of the routing table owner
+ * @param prefix id of the bucket where we want that identifier to be
*/
unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
{
return n ^ id;
}
-/**
- * \brief Returns the prefix of an identifier.
+/** @brief Returns the prefix of an identifier.
* The prefix is the id of the bucket in which the remote identifier xor our identifier should be stored.
* @param id : bigunsigned int id to test
* @param nb_bits : key size
return 0;
}
-/**
- * \brief Gets the mailbox name of a host given its identifier
+/** @brief Gets the mailbox name of a host given its identifier
*/
void get_node_mailbox(unsigned int id, char *mailbox)
{
sprintf(mailbox, "%0*x", MAILBOX_NAME_SIZE, id);
}
-/**
- * Constructor, build a new contact information.
- */
+/** Constructor, build a new contact information. */
node_contact_t node_contact_new(unsigned int id, unsigned int distance)
{
node_contact_t contact = xbt_new(s_node_contact_t, 1);
return contact;
}
-/**
- * Builds a contact information from a contact information
- */
+/** Builds a contact information from a contact information */
node_contact_t node_contact_copy(node_contact_t node_contact)
{
node_contact_t contact = xbt_new(s_node_contact_t, 1);
return contact;
}
-/**
- * Destructor
- * @param contact the node_contact to kill.
- */
+/** Destructor */
void node_contact_free(node_contact_t contact)
{
xbt_free(contact);
-/* Copyright (c) 2012, 2014-2015. The SimGrid Team.
+/* Copyright (c) 2012, 2014-2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "simgrid/msg.h"
#include "common.h"
-
#include "answer.h"
#include "routing_table.h"
-/**
- * Information about a foreign node
- */
+
+/* Information about a foreign node */
typedef struct s_node_contact {
unsigned int id; //The node identifier
unsigned int distance; //The distance from the node
} s_node_contact_t, *node_contact_t;
-/*
- * Node data
- */
+/* Node data */
typedef struct s_node {
unsigned int id; //node id - 160 bits
routing_table_t table; //node routing table
// node functions
node_t node_init(unsigned int id);
void node_free(node_t node);
-
void node_routing_table_update(node_t node, unsigned int id);
answer_t node_find_closest(node_t node, unsigned int destination_id);
-
// identifier functions
unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix);
unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits);
-/* Copyright (c) 2012-2015. The SimGrid Team.
+/* Copyright (c) 2012-2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "simgrid/msg.h"
#include "xbt/log.h"
#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_routing_table,
- "Messages specific for this msg example");
-/**
- * \brief Initialization of a node routing table.
- */
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_routing_table, "Messages specific for this msg example");
+
+/** @brief Initialization of a node routing table. */
routing_table_t routing_table_init(unsigned int node_id)
{
unsigned int i;
return table;
}
-/**
- * \brief Frees the routing table
- */
+/** @brief Frees the routing table */
void routing_table_free(routing_table_t table)
{
unsigned int i;
xbt_free(table);
}
-/**
- * Returns if the routing table contains the id.
- */
+/** Returns if the routing table contains the id. */
unsigned int routing_table_contains(routing_table_t table, unsigned int node_id)
{
bucket_t bucket = routing_table_find_bucket(table, node_id);
return bucket_contains(bucket, node_id);
}
-/**
- * @brief prints the routing table, to debug stuff.
- */
+/**@brief prints the routing table, to debug stuff. */
void routing_table_print(routing_table_t table)
{
unsigned int i, j, value;
}
}
-/**
- * Finds an identifier in a bucket and returns its position
- * or returns -1 if it doesn't exists
+/** @brief Finds an identifier in a bucket and returns its position or returns -1 if it doesn't exists
* @param bucket the bucket in which we try to find our identifier
* @param id the id
*/
unsigned int bucket_find_id(bucket_t bucket, unsigned int id)
{
- unsigned int i, length = xbt_dynar_length(bucket->nodes);
- for (i = 0; i < length; i++) { //TODO: Use foreach maybe ?
- if (id == xbt_dynar_get_as(bucket->nodes, i, unsigned int)) {
+ unsigned int i, current_id;
+ xbt_dynar_foreach(bucket->nodes, i, current_id){
+ if (id == current_id){
return i;
}
}
return -1;
}
-/**
- * Returns if the bucket contains an identifier.
- */
+/** Returns if the bucket contains an identifier. */
unsigned int bucket_contains(bucket_t bucket, unsigned int id)
{
- unsigned int length = xbt_dynar_length(bucket->nodes), i = 0;
- for (i = 0; i < length; i++) {
- if (id == xbt_dynar_get_as(bucket->nodes, i, unsigned int)) {
- return 1;
- }
- }
- return 0;
+ return xbt_dynar_member(bucket->nodes, &id);
}
-/**
- * Fins the corresponding bucket in a routing table for a given identifier
+/** @brief Finds the corresponding bucket in a routing table for a given identifier
* @param table the routing table
* @param id the identifier
* @return the bucket in which the the identifier would be.
{
unsigned int xor_number = table->id ^ id;
unsigned int prefix = get_node_prefix(xor_number, identifier_size);
- xbt_assert(prefix >= 0
- && prefix <= identifier_size,
- "Tried to return a bucket that doesn't exist.");
+ xbt_assert(prefix >= 0 && prefix <= identifier_size, "Tried to return a bucket that doesn't exist.");
bucket_t bucket = &table->buckets[prefix];
return bucket;
}
#define _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE
#include "common.h"
#include <xbt/dynar.h>
-/*
- * Routing table bucket
- */
+
+/* Routing table bucket */
typedef struct s_bucket {
xbt_dynar_t nodes; //Nodes in the bucket.
unsigned int id; //bucket id
} s_bucket_t, *bucket_t;
-/*
- * Node routing table
- */
+/* Node routing table */
typedef struct s_routing_table {
unsigned int id; //node id of the client's routing table
s_bucket_t *buckets; //Node bucket list - 160 sized.
} s_routing_table_t, *routing_table_t;
+
// bucket functions
unsigned int bucket_find_id(bucket_t bucket, unsigned int id);
unsigned int bucket_contains(bucket_t bucket, unsigned int id);
+
// routing table functions
routing_table_t routing_table_init(unsigned int node_id);
void routing_table_free(routing_table_t table);
-unsigned int routing_table_contains(routing_table_t table,
- unsigned int node_id);
+unsigned int routing_table_contains(routing_table_t table, unsigned int node_id);
void routing_table_print(routing_table_t table);
bucket_t routing_table_find_bucket(routing_table_t table, unsigned int id);
-
#endif /* _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE */
-/* Copyright (c) 2012, 2014. The SimGrid Team.
+/* Copyright (c) 2012, 2014, 2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "task.h"
#include "answer.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task,
- "Messages specific for this msg example");
-/**
- * Creates a new "find node" task
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task, "Messages specific for this msg example");
+
+/** @brief Creates a new "find node" task
* @param sender_id the id of the node who sends the task
* @param destination_id the id the sender is trying to find
* @param hostname the hostname of the node, for logging purposes
*/
-msg_task_t task_new_find_node(unsigned int sender_id,
- unsigned int destination_id, char *mailbox,
- const char *hostname)
+msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname)
{
-
task_data_t data = xbt_new(s_task_data_t, 1);
data->type = TASK_FIND_NODE;
data->answer_to = mailbox;
data->issuer_host_name = hostname;
-
msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
return task;
}
-/**
- * Creates a new "answer to find node" task
+/** @brief Creates a new "answer to find node" task
* @param sender_id the node who sent the task
* @param destination_id the node that should be found
* @param answer the answer to send
* @param mailbox The mailbox of the sender
* @param hostname sender hostname
*/
-msg_task_t task_new_find_node_answer(unsigned int sender_id,
- unsigned int destination_id,
- answer_t answer, char *mailbox,
- const char *hostname)
+msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destination_id, answer_t answer,
+ char *mailbox, const char *hostname)
{
-
task_data_t data = xbt_new(s_task_data_t, 1);
data->type = TASK_FIND_NODE_ANSWER;
return task;
}
-/**
- * Creates a new "ping" task
+/** @brief Creates a new "ping" task
* @param sender_id : sender node identifier
* @param mailbox : mailbox where we should respond
* @param hostname : hostname of the sender, for debugging purposes
*/
-msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
- const char *hostname)
+msg_task_t task_new_ping(unsigned int sender_id, char *mailbox, const char *hostname)
{
-
task_data_t data = xbt_new(s_task_data_t, 1);
data->type = TASK_PING;
return task;
}
-/**
- * Creates a new "ping answer" task
+/** @brief Creates a new "ping answer" task
* @param sender_id : sender node identifier
* @param mailbox : mailbox of the sender
* @param hostname : hostname of the sender, for debugging purposes
*/
-msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
- const char *hostname)
+msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox, const char *hostname)
{
-
task_data_t data = xbt_new(s_task_data_t, 1);
data->type = TASK_PING_ANSWER;
return task;
}
-/**
- * Destroys a task and its data
+/** @brief Destroys a task and its data
* @param task the task that'll be destroyed
*/
void task_free(msg_task_t task)
xbt_free(data);
MSG_task_destroy(task);
-
}
-/**
- * Destroys a task and its data (taking a void* pointer
+/** @brief Destroys a task and its data (taking a void* pointer
* @param task The task that'll be destroyed
*/
void task_free_v(void *task)
-/* Copyright (c) 2012, 2014-2015. The SimGrid Team.
+/* Copyright (c) 2012, 2014-2016. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "common.h"
#include "node.h"
#include "simgrid/msg.h"
-/**
- * Types of tasks exchanged
- */
+
+/* Types of tasks exchanged */
typedef enum {
TASK_FIND_NODE,
TASK_FIND_NODE_ANSWER,
TASK_PING_ANSWER,
TASK_LEAVING
} e_task_type_t;
-/**
- * Data attached with the tasks
- */
+
+/* Data attached with the tasks */
typedef struct s_task_data {
e_task_type_t type;
unsigned int sender_id; //Id of the guy who sent the task
} s_task_data_t, *task_data_t;
//Task handling functions
-msg_task_t task_new_find_node(unsigned int sender_id,
- unsigned int destination_id, char *mailbox,
- const char *hostname);
-
-msg_task_t task_new_find_node_answer(unsigned int sender_id,
- unsigned int destination_id,
- answer_t answer, char *mailbox,
- const char *hostname);
-
-msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
- const char *hostname);
-msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
- const char *hostname);
+msg_task_t task_new_find_node(unsigned int sender_id, unsigned int destination_id, char *mailbox, const char *hostname);
+msg_task_t task_new_find_node_answer(unsigned int sender_id, unsigned int destination_id, answer_t answer,
+ char *mailbox, const char *hostname);
+msg_task_t task_new_ping(unsigned int sender_id, char *mailbox, const char *hostname);
+msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox, const char *hostname);
void task_free(msg_task_t task);
void task_free_v(void *task);
#endif /* _MSG_KADEMLIA_EXAMPLES_TASK */