Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: apply some sonar advices
[simgrid.git] / src / surf / network_cm02.hpp
1 /* Copyright (c) 2013-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SURF_NETWORK_CM02_HPP_
7 #define SURF_NETWORK_CM02_HPP_
8
9 #include <xbt/base.h>
10
11 #include "src/kernel/resource/NetworkModel.hpp"
12 #include "src/kernel/resource/StandardLinkImpl.hpp"
13 #include "xbt/graph.h"
14 #include "xbt/string.hpp"
15
16 /***********
17  * Classes *
18  ***********/
19
20 namespace simgrid::kernel::resource {
21
22 class XBT_PRIVATE NetworkCm02Model;
23 class XBT_PRIVATE NetworkCm02Action;
24 class XBT_PRIVATE NetworkSmpiModel;
25
26 /*********
27  * Model *
28  *********/
29
30 class NetworkCm02Model : public NetworkModel {
31   /** @brief Get route information (2-way) */
32   bool comm_get_route_info(const s4u::Host* src, const s4u::Host* dst, /* OUT */ double& latency,
33                            std::vector<StandardLinkImpl*>& route, std::vector<StandardLinkImpl*>& back_route,
34                            std::unordered_set<kernel::routing::NetZoneImpl*>& netzones) const;
35   /** @brief Create network action for this communication */
36   NetworkCm02Action* comm_action_create(s4u::Host* src, s4u::Host* dst, double size,
37                                         const std::vector<StandardLinkImpl*>& route, bool failed);
38   /** @brief Expand link contraint considering this new communication action */
39   void comm_action_expand_constraints(const s4u::Host* src, const s4u::Host* dst, const NetworkCm02Action* action,
40                                       const std::vector<StandardLinkImpl*>& route,
41                                       const std::vector<StandardLinkImpl*>& back_route) const;
42   /** @brief Set communication bounds for latency and bandwidth */
43   void comm_action_set_bounds(const s4u::Host* src, const s4u::Host* dst, double size, NetworkCm02Action* action,
44                               const std::vector<StandardLinkImpl*>& route,
45                               const std::unordered_set<kernel::routing::NetZoneImpl*>& netzones, double rate);
46   /** @brief Create maxmin variable in communication action */
47   void comm_action_set_variable(NetworkCm02Action* action, const std::vector<StandardLinkImpl*>& route,
48                                 const std::vector<StandardLinkImpl*>& back_route);
49
50 public:
51   explicit NetworkCm02Model(const std::string& name);
52   StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
53   StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
54   void update_actions_state_lazy(double now, double delta) override;
55   void update_actions_state_full(double now, double delta) override;
56   Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
57   void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override;
58   void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override;
59
60 protected:
61   virtual void check_lat_factor_cb();
62   virtual void check_bw_factor_cb();
63
64 private:
65   std::function<NetworkFactorCb> lat_factor_cb_;
66   std::function<NetworkFactorCb> bw_factor_cb_;
67 };
68
69 /************
70  * Resource *
71  ************/
72
73 class NetworkCm02Link : public StandardLinkImpl {
74 public:
75   NetworkCm02Link(const std::string& name, double bandwidth, lmm::System* system);
76   void apply_event(kernel::profile::Event* event, double value) override;
77   void set_bandwidth(double value) override;
78   void set_latency(double value) override;
79 };
80
81 /**********
82  * Action *
83  **********/
84 class NetworkCm02Action : public NetworkAction {
85   friend Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
86
87 public:
88   using NetworkAction::NetworkAction;
89   void update_remains_lazy(double now) override;
90 };
91 } // namespace simgrid::kernel::resource
92 #endif /* SURF_NETWORK_CM02_HPP_ */