{
xbt_assert((bucket != nullptr), "Provided a NULL bucket");
- for (auto const& id : bucket->nodes) {
+ for (auto const& id : bucket->nodes_) {
unsigned int distance = id ^ destination_id_;
nodes_.push_back(std::pair<unsigned int, unsigned int>(id, distance));
}
}
-}
+} // namespace kademlia
bool destinationFound() const;
void addBucket(const kademlia::Bucket* bucket);
};
-}
+} // namespace kademlia
#endif
Message(const Message&) = delete;
Message& operator=(const Message&) = delete;
};
-}
+} // namespace kademlia
#endif
Bucket* bucket = table.findBucket(id);
// check if the id is already in the bucket.
- auto id_pos = std::find(bucket->nodes.begin(), bucket->nodes.end(), id);
+ auto id_pos = std::find(bucket->nodes_.begin(), bucket->nodes_.end(), id);
- if (id_pos == bucket->nodes.end()) {
+ if (id_pos == bucket->nodes_.end()) {
/* We check if the bucket is full or not. If it is, we evict an old element */
- if (bucket->nodes.size() >= BUCKET_SIZE) {
- bucket->nodes.pop_back();
+ if (bucket->nodes_.size() >= BUCKET_SIZE) {
+ bucket->nodes_.pop_back();
}
- bucket->nodes.push_front(id);
+ bucket->nodes_.push_front(id);
XBT_VERB("I'm adding to my routing table %08x", id);
} else {
// We push the element to the front
- bucket->nodes.erase(id_pos);
- bucket->nodes.push_front(id);
+ bucket->nodes_.erase(id_pos);
+ bucket->nodes_.push_front(id);
XBT_VERB("I'm updating %08x", id);
}
}
for (int i = 1; answer->getSize() < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) {
/* We check the previous buckets */
if (bucket_id - i >= 0) {
- const Bucket* bucket_p = &table.buckets[bucket_id - i];
+ const Bucket* bucket_p = &table.getBucketAt(bucket_id - i);
answer->addBucket(bucket_p);
}
/* We check the next buckets */
if (bucket_id + i <= IDENTIFIER_SIZE) {
- const Bucket* bucket_n = &table.buckets[bucket_id + i];
+ const Bucket* bucket_n = &table.getBucketAt(bucket_id + i);
answer->addBucket(bucket_n);
}
}
// Sending the answer
msg->answer_to_->put_init(answer, 1)->detach(kademlia::destroy);
}
+
+void Node::displaySuccessRate()
+{
+ XBT_INFO("%u/%u FIND_NODE have succeeded", find_node_success, find_node_success + find_node_failed);
}
+} // namespace kademlia
/**@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
class Node {
unsigned int id_; // node id - 160 bits
RoutingTable table; // node routing table
+ unsigned int find_node_success = 0; // Number of find_node which have succeeded.
+ unsigned int find_node_failed = 0; // Number of find_node which have failed.
public:
simgrid::s4u::CommPtr receive_comm = nullptr;
void* received_msg = nullptr;
- unsigned int find_node_success = 0; // Number of find_node which have succeeded.
- unsigned int find_node_failed = 0; // Number of find_node which have failed.
explicit Node(unsigned int node_id) : id_(node_id), table(node_id) {}
Node(const Node&) = delete;
Node& operator=(const Node&) = delete;
bool findNode(unsigned int id_to_find, bool count_in_stats);
void randomLookup();
void handleFindNode(const Message* msg);
+ void displaySuccessRate();
};
-}
+} // namespace kademlia
// 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);
/** @brief Initialization of a node routing table. */
RoutingTable::RoutingTable(unsigned int node_id) : id_(node_id)
{
- buckets.reserve(IDENTIFIER_SIZE + 1);
+ buckets_.reserve(IDENTIFIER_SIZE + 1);
for (unsigned int i = 0; i < IDENTIFIER_SIZE + 1; i++)
- buckets.emplace_back(i);
+ buckets_.emplace_back(i);
}
void RoutingTable::print() const
XBT_INFO("Routing table of %08x:", id_);
for (unsigned int i = 0; i <= IDENTIFIER_SIZE; i++) {
- if (not buckets[i].nodes.empty()) {
+ if (not buckets_[i].nodes_.empty()) {
XBT_INFO("Bucket number %u: ", i);
int j = 0;
- for (auto value : buckets[i].nodes) {
+ for (auto value : buckets_[i].nodes_) {
XBT_INFO("Element %d: %08x", j, value);
j++;
}
unsigned int xor_number = id_ ^ id;
unsigned int prefix = get_node_prefix(xor_number, IDENTIFIER_SIZE);
xbt_assert(prefix <= IDENTIFIER_SIZE, "Tried to return a bucket that doesn't exist.");
- return &buckets[prefix];
+ return &buckets_[prefix];
}
/** Returns if the routing table contains the id. */
bool RoutingTable::contains(unsigned int node_id)
{
const Bucket* bucket = findBucket(node_id);
- return std::find(bucket->nodes.begin(), bucket->nodes.end(), node_id) != bucket->nodes.end();
-}
+ return std::find(bucket->nodes_.begin(), bucket->nodes_.end(), node_id) != bucket->nodes_.end();
}
+} // namespace kademlia
class Bucket {
unsigned int id_; // bucket id
public:
- std::deque<unsigned int> nodes; // Nodes in the bucket.
+ std::deque<unsigned int> nodes_; // Nodes in the bucket.
unsigned int getId() const { return id_; }
explicit Bucket(unsigned int id) noexcept : id_(id) {}
};
/* Node routing table */
class RoutingTable {
unsigned int id_; // node id of the client's routing table
+ std::vector<Bucket> buckets_; // Node bucket list
public:
- std::vector<Bucket> buckets; // Node bucket list - 160 sized.
explicit RoutingTable(unsigned int node_id);
RoutingTable(const RoutingTable&) = delete;
RoutingTable& operator=(const RoutingTable&) = delete;
void print() const;
Bucket* findBucket(unsigned int id);
+ const Bucket& getBucketAt(unsigned int pos) const { return buckets_[pos]; }
bool contains(unsigned int node_id);
};
-}
+} // namespace kademlia
#endif
XBT_INFO("I couldn't join the network :(");
}
XBT_DEBUG("I'm leaving the network");
- XBT_INFO("%u/%u FIND_NODE have succeeded", node.find_node_success, node.find_node_success + node.find_node_failed);
+ node.displaySuccessRate();
}
/** @brief Main function */
namespace kademlia {
class Answer;
class Message;
-}
+} // namespace kademlia
constexpr double FIND_NODE_TIMEOUT = 10.0;
constexpr double FIND_NODE_GLOBAL_TIMEOUT = 50.0;
void StateType::set_event(const std::string& value_name)
{
- events_.push_back(new StateEvent(issuer_, this, PAJE_SetState, get_entity_value(value_name), nullptr));
+ events_.push_back(new StateEvent(get_issuer(), this, PAJE_SetState, get_entity_value(value_name), nullptr));
}
void StateType::push_event(const std::string& value_name, TIData* extra)
{
- events_.push_back(new StateEvent(issuer_, this, PAJE_PushState, get_entity_value(value_name), extra));
+ events_.push_back(new StateEvent(get_issuer(), this, PAJE_PushState, get_entity_value(value_name), extra));
}
void StateType::push_event(const std::string& value_name)
{
- events_.push_back(new StateEvent(issuer_, this, PAJE_PushState, get_entity_value(value_name), nullptr));
+ events_.push_back(new StateEvent(get_issuer(), this, PAJE_PushState, get_entity_value(value_name), nullptr));
}
void StateType::pop_event()
void StateType::pop_event(TIData* extra)
{
- events_.push_back(new StateEvent(issuer_, this, PAJE_PopState, nullptr, extra));
+ events_.push_back(new StateEvent(get_issuer(), this, PAJE_PopState, nullptr, extra));
}
void VariableType::instr_event(double now, double delta, const char* resource, double value)
void VariableType::set_event(double timestamp, double value)
{
- events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_SetVariable, value));
+ events_.push_back(new VariableEvent(timestamp, get_issuer(), this, PAJE_SetVariable, value));
}
void VariableType::add_event(double timestamp, double value)
{
- events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_AddVariable, value));
+ events_.push_back(new VariableEvent(timestamp, get_issuer(), this, PAJE_AddVariable, value));
}
void VariableType::sub_event(double timestamp, double value)
{
- events_.push_back(new VariableEvent(timestamp, issuer_, this, PAJE_SubVariable, value));
+ events_.push_back(new VariableEvent(timestamp, get_issuer(), this, PAJE_SubVariable, value));
}
void LinkType::start_event(Container* startContainer, const std::string& value, const std::string& key)
void LinkType::start_event(Container* startContainer, const std::string& value, const std::string& key, int size)
{
- new LinkEvent(issuer_, this, PAJE_StartLink, startContainer, value, key, size);
+ new LinkEvent(get_issuer(), this, PAJE_StartLink, startContainer, value, key, size);
}
void LinkType::end_event(Container* endContainer, const std::string& value, const std::string& key)
{
- new LinkEvent(issuer_, this, PAJE_EndLink, endContainer, value, key, -1);
+ new LinkEvent(get_issuer(), this, PAJE_EndLink, endContainer, value, key, -1);
}
Type* Type::by_name(const std::string& name)
std::string name_;
std::string color_;
Type* father_;
+ std::map<std::string, std::unique_ptr<Type>> children_;
+ Container* issuer_ = nullptr;
+
+protected:
+ Container* get_issuer() const { return issuer_; }
public:
static xbt::signal<void(Type&, e_event_type event_type)> on_creation;
- std::map<std::string, std::unique_ptr<Type>> children_;
- Container* issuer_ = nullptr;
Type(e_event_type event_type, const std::string& name, const std::string& alias, const std::string& color,
Type* father);
const char* get_cname() { return name_.c_str(); }
const std::string& get_color() const { return color_; }
Type* get_father() const { return father_; }
+ const std::map<std::string, std::unique_ptr<Type>>& get_children() { return children_; }
bool is_colored() { return not color_.empty(); }
Type* by_name(const std::string& name);
if (root->get_name() == "LINK")
root->by_name_or_create(std::string("b") + new_typename, color);
- for (auto const& elm : root->children_) {
+ for (auto const& elm : root->get_children()) {
recursiveNewVariableType(new_typename, color, elm.second.get());
}
}
if (root->get_name() == father_type) {
root->by_name_or_create(new_typename, color);
}
- for (auto const& elm : root->children_)
+ for (auto const& elm : root->get_children())
recursiveNewUserVariableType(father_type, new_typename, color, elm.second.get());
}
if (root->get_name() == father_type)
root->by_name_or_create<simgrid::instr::StateType>(new_typename);
- for (auto const& elm : root->children_)
+ for (auto const& elm : root->get_children())
recursiveNewUserStateType(father_type, new_typename, elm.second.get());
}
if (root->get_name() == type_name)
static_cast<simgrid::instr::StateType*>(root)->add_entity_value(val, color);
- for (auto const& elm : root->children_)
+ for (auto const& elm : root->get_children())
recursiveNewValueForUserStateType(type_name, val, color, elm.second.get());
}
s4u::Disk piface_;
double read_bw_;
double write_bw_;
+ lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
+ lmm::Constraint* constraint_read_; /* Constraint for maximum write bandwidth*/
public:
DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw);
/** @brief Public interface */
s4u::Disk* get_iface() { return &piface_; }
+ s4u::Host* get_host() const { return host_; }
+ void set_host(s4u::Host* host) { host_ = host; }
+
double get_read_bandwidth() { return read_bw_; }
double get_write_bandwidth() { return write_bw_; }
+ lmm::Constraint* get_read_constraint() const { return constraint_read_; }
+ lmm::Constraint* get_write_constraint() const { return constraint_write_; }
/** @brief Check if the Storage is used (if an action currently uses its resources) */
bool is_used() override;
-
void apply_event(profile::Event* event, double value) override;
-
void turn_on() override;
void turn_off() override;
- s4u::Host* get_host() const { return host_; }
- void set_host(s4u::Host* host) { host_ = host; }
-
void destroy(); // Must be called instead of the destructor
virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
virtual DiskAction* read(sg_size_t size) = 0;
virtual DiskAction* write(sg_size_t size) = 0;
-
- lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
- lmm::Constraint* constraint_read_; /* Constraint for maximum write bandwidth*/
};
/**********
model->get_maxmin_system()->expand(disk->get_constraint(), get_variable(), 1.0);
switch (type) {
case s4u::Io::OpType::READ:
- model->get_maxmin_system()->expand(disk->constraint_read_, get_variable(), 1.0);
+ model->get_maxmin_system()->expand(disk->get_read_constraint(), get_variable(), 1.0);
break;
case s4u::Io::OpType::WRITE:
- model->get_maxmin_system()->expand(disk->constraint_write_, get_variable(), 1.0);
+ model->get_maxmin_system()->expand(disk->get_write_constraint(), get_variable(), 1.0);
break;
default:
THROW_UNIMPLEMENTED;