Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 17 Apr 2020 11:15:46 +0000 (13:15 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 21 Apr 2020 08:11:27 +0000 (10:11 +0200)
14 files changed:
examples/s4u/dht-kademlia/answer.cpp
examples/s4u/dht-kademlia/answer.hpp
examples/s4u/dht-kademlia/message.hpp
examples/s4u/dht-kademlia/node.cpp
examples/s4u/dht-kademlia/node.hpp
examples/s4u/dht-kademlia/routing_table.cpp
examples/s4u/dht-kademlia/routing_table.hpp
examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp
examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp
src/instr/instr_paje_types.cpp
src/instr/instr_paje_types.hpp
src/instr/instr_platform.cpp
src/kernel/resource/DiskImpl.hpp
src/surf/disk_s19.cpp

index 7fa8655..6d5515c 100644 (file)
@@ -65,9 +65,9 @@ void Answer::addBucket(const Bucket* bucket)
 {
   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
index 34896d6..de5e1c9 100644 (file)
@@ -29,6 +29,6 @@ public:
   bool destinationFound() const;
   void addBucket(const kademlia::Bucket* bucket);
 };
-}
+} // namespace kademlia
 
 #endif
index 35ec478..15f5e5f 100644 (file)
@@ -38,5 +38,5 @@ public:
   Message(const Message&) = delete;
   Message& operator=(const Message&) = delete;
 };
-}
+} // namespace kademlia
 #endif
index fc2a7e4..d331cc3 100644 (file)
@@ -122,19 +122,19 @@ void Node::routingTableUpdate(unsigned int id)
   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);
   }
 }
@@ -159,12 +159,12 @@ Answer* Node::findClosest(unsigned int destination_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);
     }
   }
@@ -280,7 +280,12 @@ void Node::handleFindNode(const Message* msg)
   // 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
index dc36ae2..ab64fa7 100644 (file)
@@ -16,11 +16,11 @@ namespace kademlia {
 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;
@@ -34,8 +34,9 @@ public:
   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);
index c94ae3c..3bd9e5e 100644 (file)
@@ -14,9 +14,9 @@ namespace kademlia {
 /** @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
@@ -24,10 +24,10 @@ 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++;
       }
@@ -44,13 +44,13 @@ Bucket* RoutingTable::findBucket(unsigned int id)
   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
index 1c609d4..dda6217 100644 (file)
@@ -16,7 +16,7 @@ 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) {}
 };
@@ -24,15 +24,16 @@ public:
 /* 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
index ac5231c..c38206c 100644 (file)
@@ -75,7 +75,7 @@ static void node(int argc, char* argv[])
     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 */
index c1fae17..347f4d6 100644 (file)
@@ -12,7 +12,7 @@
 namespace kademlia {
 class Answer;
 class Message;
-}
+} // namespace kademlia
 
 constexpr double FIND_NODE_TIMEOUT        = 10.0;
 constexpr double FIND_NODE_GLOBAL_TIMEOUT = 50.0;
index 6bf9e2c..7cad3f6 100644 (file)
@@ -31,17 +31,17 @@ Type::Type(e_event_type event_type, const std::string& name, const std::string&
 
 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()
@@ -51,7 +51,7 @@ 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)
@@ -76,17 +76,17 @@ void VariableType::instr_event(double now, double delta, const char* resource, d
 
 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)
@@ -96,12 +96,12 @@ void LinkType::start_event(Container* startContainer, const std::string& value,
 
 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)
index 7d9fa60..2ce289b 100644 (file)
@@ -21,11 +21,14 @@ class Type {
   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);
@@ -36,6 +39,7 @@ public:
   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);
index 7889d97..2323f6c 100644 (file)
@@ -161,7 +161,7 @@ static void recursiveNewVariableType(const std::string& new_typename, const std:
   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());
   }
 }
@@ -177,7 +177,7 @@ static void recursiveNewUserVariableType(const std::string& father_type, const s
   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());
 }
 
@@ -193,7 +193,7 @@ static void recursiveNewUserStateType(const std::string& father_type, const std:
   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());
 }
 
@@ -208,7 +208,7 @@ static void recursiveNewValueForUserStateType(const std::string& type_name, cons
   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());
 }
 
index d536e0e..962dd9f 100644 (file)
@@ -53,6 +53,8 @@ class DiskImpl : public Resource, public xbt::PropertyHolder {
   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);
@@ -63,27 +65,24 @@ public:
 
   /** @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*/
 };
 
 /**********
index 8e849d8..66525d7 100644 (file)
@@ -96,10 +96,10 @@ DiskS19Action::DiskS19Action(Model* model, double cost, bool failed, DiskImpl* d
   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;