From: Frederic Suter Date: Fri, 17 Apr 2020 11:15:46 +0000 (+0200) Subject: please sonar X-Git-Tag: v3.26~655 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e1533d482ef3d7286eb7afc5d246b1aba8cfc1e5 please sonar --- diff --git a/examples/s4u/dht-kademlia/answer.cpp b/examples/s4u/dht-kademlia/answer.cpp index 7fa86551fd..6d5515cc76 100644 --- a/examples/s4u/dht-kademlia/answer.cpp +++ b/examples/s4u/dht-kademlia/answer.cpp @@ -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(id, distance)); } } -} +} // namespace kademlia diff --git a/examples/s4u/dht-kademlia/answer.hpp b/examples/s4u/dht-kademlia/answer.hpp index 34896d679a..de5e1c9e83 100644 --- a/examples/s4u/dht-kademlia/answer.hpp +++ b/examples/s4u/dht-kademlia/answer.hpp @@ -29,6 +29,6 @@ public: bool destinationFound() const; void addBucket(const kademlia::Bucket* bucket); }; -} +} // namespace kademlia #endif diff --git a/examples/s4u/dht-kademlia/message.hpp b/examples/s4u/dht-kademlia/message.hpp index 35ec478e58..15f5e5fb87 100644 --- a/examples/s4u/dht-kademlia/message.hpp +++ b/examples/s4u/dht-kademlia/message.hpp @@ -38,5 +38,5 @@ public: Message(const Message&) = delete; Message& operator=(const Message&) = delete; }; -} +} // namespace kademlia #endif diff --git a/examples/s4u/dht-kademlia/node.cpp b/examples/s4u/dht-kademlia/node.cpp index fc2a7e481f..d331cc361b 100644 --- a/examples/s4u/dht-kademlia/node.cpp +++ b/examples/s4u/dht-kademlia/node.cpp @@ -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 diff --git a/examples/s4u/dht-kademlia/node.hpp b/examples/s4u/dht-kademlia/node.hpp index dc36ae20fb..ab64fa7252 100644 --- a/examples/s4u/dht-kademlia/node.hpp +++ b/examples/s4u/dht-kademlia/node.hpp @@ -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); diff --git a/examples/s4u/dht-kademlia/routing_table.cpp b/examples/s4u/dht-kademlia/routing_table.cpp index c94ae3c01f..3bd9e5eda1 100644 --- a/examples/s4u/dht-kademlia/routing_table.cpp +++ b/examples/s4u/dht-kademlia/routing_table.cpp @@ -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 diff --git a/examples/s4u/dht-kademlia/routing_table.hpp b/examples/s4u/dht-kademlia/routing_table.hpp index 1c609d4cec..dda6217439 100644 --- a/examples/s4u/dht-kademlia/routing_table.hpp +++ b/examples/s4u/dht-kademlia/routing_table.hpp @@ -16,7 +16,7 @@ namespace kademlia { class Bucket { unsigned int id_; // bucket id public: - std::deque nodes; // Nodes in the bucket. + std::deque 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 buckets_; // Node bucket list public: - std::vector 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 diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp index ac5231cf8a..c38206c99c 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp @@ -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 */ diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp index c1fae1712c..347f4d6190 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp @@ -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; diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 6bf9e2c0ca..7cad3f6a9f 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -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) diff --git a/src/instr/instr_paje_types.hpp b/src/instr/instr_paje_types.hpp index 7d9fa60ee7..2ce289b7d7 100644 --- a/src/instr/instr_paje_types.hpp +++ b/src/instr/instr_paje_types.hpp @@ -21,11 +21,14 @@ class Type { std::string name_; std::string color_; Type* father_; + std::map> children_; + Container* issuer_ = nullptr; + +protected: + Container* get_issuer() const { return issuer_; } public: static xbt::signal on_creation; - std::map> 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>& get_children() { return children_; } bool is_colored() { return not color_.empty(); } Type* by_name(const std::string& name); diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 7889d9717c..2323f6c088 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -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(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(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()); } diff --git a/src/kernel/resource/DiskImpl.hpp b/src/kernel/resource/DiskImpl.hpp index d536e0e8c2..962dd9f999 100644 --- a/src/kernel/resource/DiskImpl.hpp +++ b/src/kernel/resource/DiskImpl.hpp @@ -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*/ }; /********** diff --git a/src/surf/disk_s19.cpp b/src/surf/disk_s19.cpp index 8e849d8353..66525d7eee 100644 --- a/src/surf/disk_s19.cpp +++ b/src/surf/disk_s19.cpp @@ -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;