set(dht-chord_files Main ChordTask Common FindSuccessorAnswerTask FindSuccessorTask
GetPredecessorAnswerTask GetPredecessorTask Node NotifyTask)
set(dht-kademlia_files Main Answer Bucket Common Contact FindNodeAnswerTask FindNodeTask
- KademliaTask Node PingAnswerTask PingTask RoutingTable)
+ KademliaTask Node RoutingTable)
set(trace-pingpong_files Main PingPongTask Receiver Sender)
set(energy-consumption_files Main EnergyConsumer)
set(energy-pstate_files Main PstateRunner)
public static final int FIND_NODE_TIMEOUT = 10;
/* Global timeout for a FIND_NODE request */
public static final int FIND_NODE_GLOBAL_TIMEOUT = 50;
- /* Timeout for a "PING" request */
- public static final int PING_TIMEOUT = 35;
public static final int MAX_STEPS = 10;
public static final int JOIN_BUCKETS_QUERIES = 1;
return destinationFound;
}
- /**
- * @brief Sends a "PING" request to a node
- * @param destination Ping destination id.
- */
- public void ping(int destination) {
- boolean destinationFound = false;
- double timeout = Msg.getClock() + Common.PING_TIMEOUT;
- PingTask pingTask = new PingTask(this.id);
- /* Sending the ping task */
- pingTask.dsend(Integer.toString(destination));
- do {
- try {
- Task task = Task.receive(Integer.toString(this.id),Common.PING_TIMEOUT);
- if (task instanceof PingAnswerTask) {
- PingAnswerTask answerTask = (PingAnswerTask)task;
- if (answerTask.getSenderId() == destination) {
- this.table.update(destination);
- destinationFound = true;
- } else {
- handleTask(task);
- }
- } else {
- handleTask(task);
- }
- waitFor(1);
- }
- catch (Exception ex) {
- Msg.debug("Caught exception: " + ex);
- }
- } while (Msg.getClock() < timeout && !destinationFound);
- }
-
/**
* @brief Sends a "FIND_NODE" request (task) to a node we know.
* @param id Id of the node we are querying
if (task instanceof FindNodeTask) {
handleFindNode((FindNodeTask)task);
}
- else if (task instanceof PingTask) {
- handlePing((PingTask)task);
- }
}
}
FindNodeAnswerTask taskToSend = new FindNodeAnswerTask(this.id,task.getDestination(),answer);
taskToSend.dsend(Integer.toString(task.getSenderId()));
}
-
- public void handlePing(PingTask task) {
- Msg.debug("Received a PING from " + task.getSenderId());
- PingAnswerTask taskToSend = new PingAnswerTask(this.id);
- taskToSend.dsend(Integer.toString(task.getSenderId()));
- }
}
+++ /dev/null
-/* Copyright (c) 2012-2019. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-package dht.kademlia;
-
-public class PingAnswerTask extends KademliaTask {
- public PingAnswerTask(int senderId) {
- super(senderId);
- }
-}
+++ /dev/null
-/* Copyright (c) 2012-2019. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-package dht.kademlia;
-
-public class PingTask extends KademliaTask {
- public PingTask(int senderId) {
- super(senderId);
- }
-}
#define RECEIVE_TIMEOUT 1
-#define ping_timeout 55
#define find_node_timeout 10
#define find_node_global_timeout 50
return destination_found;
}
-/** @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 ping(node_t node, unsigned int id_to_ping)
-{
- char mailbox[MAILBOX_NAME_SIZE];
- snprintf(mailbox, MAILBOX_NAME_SIZE, "%u", id_to_ping);
-
- 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 task_received = NULL;
-
- XBT_VERB("PING %08x", id_to_ping);
-
- //Check that we aren't trying to ping ourselves
- if (id_to_ping == node->id) {
- return 1;
- }
-
- /* Sending the ping task */
- MSG_task_dsend(ping_task, mailbox, task_free_v);
- do {
- task_received = NULL;
- msg_error_t status =
- 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.
- task_data_t data = MSG_task_get_data(task_received);
- xbt_assert((data != NULL), "didn't receive any data...");
- if (data->type == TASK_PING_ANSWER && id_to_ping == data->sender_id) {
- XBT_VERB("Ping to %s succeeded", mailbox);
- node_routing_table_update(node, data->sender_id);
- task_free(task_received);
- return 1; // Destination found, ping succeeded!
- } else {
- //If it's not our answer, we answer the query anyway.
- handle_task(node, task_received);
- }
- }
- } while (MSG_get_clock() < timeout);
-
- if (MSG_get_clock() >= timeout) {
- XBT_DEBUG("Ping to %s has timeout.", mailbox);
- return 0;
- }
- XBT_DEBUG("It seems that %s is offline...", mailbox);
- return -1;
-}
-
/** @brief Does a pseudo-random lookup for someone in the system
* @param node caller node data
*/
case TASK_FIND_NODE_ANSWER:
XBT_DEBUG("Received a wrong answer for a FIND_NODE");
break;
- case TASK_PING:
- handle_ping(node, data);
- break;
default:
break;
}
MSG_task_dsend(task, data->answer_to, task_free_v);
}
-/** @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);
- //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_dsend(task, data->answer_to, task_free_v);
-}
-
/** @brief Main function */
int main(int argc, char *argv[])
{
//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 ping(node_t node, unsigned int id_to_ping);
void random_lookup(node_t node);
void send_find_node(node_t node, unsigned int id, unsigned int destination);
void handle_task(node_t node, msg_task_t task);
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 */
return 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)
-{
- task_data_t data = xbt_new(s_task_data_t, 1);
-
- data->type = TASK_PING;
- data->sender_id = sender_id;
- data->destination_id = 0;
- data->answer = NULL;
- data->answer_to = mailbox;
- data->issuer_host_name = hostname;
-
- msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
-
- return 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)
-{
- task_data_t data = xbt_new(s_task_data_t, 1);
-
- data->type = TASK_PING_ANSWER;
- data->sender_id = sender_id;
- data->destination_id = 0;
- data->answer = NULL;
- data->answer_to = mailbox;
- data->issuer_host_name = hostname;
-
- msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
-
- return task;
-}
-
/** @brief Destroys a task and its data
* @param task the task that'll be destroyed
*/
TASK_FIND_NODE_ANSWER,
TASK_FIND_VALUE,
TASK_FIND_VALUE_ANSWER,
- TASK_PING,
- TASK_PING_ANSWER,
TASK_LEAVING
} e_task_type_t;
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 */
namespace kademlia {
class Answer;
class Message;
-class Ping;
}
#define max_join_trials 4
#define RECEIVE_TIMEOUT 1
-#define ping_timeout 55
#define find_node_timeout 10
#define find_node_global_timeout 50