Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Please sonar
[simgrid.git] / src / surf / network_cm02.hpp
1 /* Copyright (c) 2013-2021. 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 "network_interface.hpp"
12 #include "simgrid/kernel/resource/NetworkModelIntf.hpp"
13 #include "xbt/graph.h"
14 #include "xbt/string.hpp"
15
16 /***********
17  * Classes *
18  ***********/
19
20 namespace simgrid {
21 namespace kernel {
22 namespace resource {
23
24 class XBT_PRIVATE NetworkCm02Model;
25 class XBT_PRIVATE NetworkCm02Action;
26 class XBT_PRIVATE NetworkSmpiModel;
27
28 /*********
29  * Model *
30  *********/
31
32 class NetworkCm02Model : public NetworkModel {
33   /** @brief Get route information (2-way) */
34   bool comm_get_route_info(const s4u::Host* src, const s4u::Host* dst, /* OUT */ double& latency,
35                            std::vector<LinkImpl*>& route, std::vector<LinkImpl*>& back_route,
36                            std::unordered_set<kernel::routing::NetZoneImpl*>& netzones) const;
37   /** @brief Create network action for this communication */
38   NetworkCm02Action* comm_action_create(s4u::Host* src, s4u::Host* dst, double size,
39                                         const std::vector<LinkImpl*>& route, bool failed);
40   /** @brief Expand link contraint considering this new communication action */
41   void comm_action_expand_constraints(const s4u::Host* src, const s4u::Host* dst, const NetworkCm02Action* action,
42                                       const std::vector<LinkImpl*>& route,
43                                       const std::vector<LinkImpl*>& back_route) const;
44   /** @brief Set communication bounds for latency and bandwidth */
45   void comm_action_set_bounds(const s4u::Host* src, const s4u::Host* dst, double size, NetworkCm02Action* action,
46                               const std::vector<LinkImpl*>& route,
47                               const std::unordered_set<kernel::routing::NetZoneImpl*>& netzones);
48   /** @brief Create maxmin variable in communication action */
49   void comm_action_set_variable(NetworkCm02Action* action, const std::vector<LinkImpl*>& route,
50                                 const std::vector<LinkImpl*>& back_route);
51
52 public:
53   explicit NetworkCm02Model(const std::string& name);
54   LinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
55   LinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
56   void update_actions_state_lazy(double now, double delta) override;
57   void update_actions_state_full(double now, double delta) override;
58   Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
59   void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb) override;
60   void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb) override;
61
62 protected:
63   virtual void check_lat_factor_cb();
64   virtual void check_bw_factor_cb();
65
66 private:
67   std::function<NetworkFactorCb> lat_factor_cb_;
68   std::function<NetworkFactorCb> bw_factor_cb_;
69 };
70
71 /************
72  * Resource *
73  ************/
74
75 class NetworkCm02Link : public LinkImpl {
76 public:
77   NetworkCm02Link(const std::string& name, double bandwidth, lmm::System* system);
78   void apply_event(kernel::profile::Event* event, double value) override;
79   void set_bandwidth(double value) override;
80   LinkImpl* set_latency(double value) override;
81 };
82
83 /**********
84  * Action *
85  **********/
86 class NetworkCm02Action : public NetworkAction {
87   friend Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
88
89 public:
90   using NetworkAction::NetworkAction;
91   void update_remains_lazy(double now) override;
92 };
93 } // namespace resource
94 } // namespace kernel
95 } // namespace simgrid
96 #endif /* SURF_NETWORK_CM02_HPP_ */