Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5acdb1216dd96e2c26e7358a5342b0d6e86b1cd1
[simgrid.git] / src / surf / network.hpp
1 #include "surf.hpp"
2 #include "xbt/fifo.h"
3 #include "xbt/graph.h"
4 #include "surf_routing.hpp"
5
6 #ifndef SURF_MODEL_NETWORK_H_
7 #define SURF_MODEL_NETWORK_H_
8
9 /***********
10  * Classes *
11  ***********/
12 class NetworkCm02Model;
13 typedef NetworkCm02Model *NetworkCm02ModelPtr;
14
15 class NetworkCm02Link;
16 typedef NetworkCm02Link *NetworkCm02LinkPtr;
17
18 class NetworkCm02LinkLmm;
19 typedef NetworkCm02LinkLmm *NetworkCm02LinkLmmPtr;
20
21 class NetworkCm02Action;
22 typedef NetworkCm02Action *NetworkCm02ActionPtr;
23
24 class NetworkCm02ActionLmm;
25 typedef NetworkCm02ActionLmm *NetworkCm02ActionLmmPtr;
26
27 /*********
28  * Tools *
29  *********/
30 extern NetworkCm02ModelPtr surf_network_model;
31
32 void net_define_callbacks(void);
33
34 /*********
35  * Model *
36  *********/
37 class NetworkCm02Model : public Model {
38 private:
39   void initialize();
40 public:
41   NetworkCm02Model(int /*i*/) : Model("network") {
42         f_networkSolve = lmm_solve;
43         m_haveGap = false;
44   };//FIXME: add network clean interface
45   NetworkCm02Model(string name) : Model(name) {
46     this->initialize();
47   }
48   NetworkCm02Model() : Model("network") {
49     this->initialize();
50   }
51   ~NetworkCm02Model() {
52         if (p_maxminSystem)
53           lmm_system_free(p_maxminSystem);
54         if (p_actionHeap)
55           xbt_heap_free(p_actionHeap);
56         if (p_modifiedSet)
57           xbt_swag_free(p_modifiedSet);
58   }
59   //FIXME:NetworkCm02LinkPtr createResource(string name);
60   NetworkCm02LinkLmmPtr createResource(const char *name,
61                                    double bw_initial,
62                                    tmgr_trace_t bw_trace,
63                                    double lat_initial,
64                                    tmgr_trace_t lat_trace,
65                                    e_surf_resource_state_t state_initial,
66                                    tmgr_trace_t state_trace,
67                                    e_surf_link_sharing_policy_t policy,
68                                    xbt_dict_t properties);
69   void updateActionsStateLazy(double now, double delta);
70   virtual void gapAppend(double /*size*/, const NetworkCm02LinkLmmPtr /*link*/, NetworkCm02ActionLmmPtr /*action*/) {};
71   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
72                                            double size, double rate);
73   xbt_dynar_t getRoute(RoutingEdgePtr src, RoutingEdgePtr dst); //FIXME: kill field? That is done by the routing nowadays
74   //FIXME: virtual void addTraces() =0;
75   void (*f_networkSolve)(lmm_system_t);
76   virtual double latencyFactor(double size);
77   virtual double bandwidthFactor(double size);
78   virtual double bandwidthConstraint(double rate, double bound, double size);
79   bool m_haveGap;
80 };
81
82 /************
83  * Resource *
84  ************/
85
86 class NetworkCm02Link : virtual public Resource {
87 public:
88   NetworkCm02Link() : p_latEvent(NULL) {};
89   NetworkCm02Link(NetworkCm02ModelPtr model, const char* name, xbt_dict_t properties)
90     : Resource(model, name, properties), p_latEvent(NULL) {};
91   virtual double getBandwidth()=0;
92   virtual double getLatency();
93   virtual bool isShared()=0;
94   /* Using this object with the public part of
95     model does not make sense */
96   double m_latCurrent;
97   tmgr_trace_event_t p_latEvent;
98 };
99
100 class NetworkCm02LinkLmm : public ResourceLmm, public NetworkCm02Link {
101 public:
102   NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char* name, xbt_dict_t properties)
103    : ResourceLmm(), NetworkCm02Link(model, name, properties) {};
104   NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
105                                    lmm_system_t system,
106                                    double constraint_value,
107                                    tmgr_history_t history,
108                                    e_surf_resource_state_t state_init,
109                                    tmgr_trace_t state_trace,
110                                    double metric_peak,
111                                    tmgr_trace_t metric_trace,
112                                    double lat_initial,
113                                    tmgr_trace_t lat_trace,
114                                e_surf_link_sharing_policy_t policy);
115   bool isShared();
116   bool isUsed();
117   double getBandwidth();
118   void updateState(tmgr_trace_event_t event_type, double value, double date);
119 };
120
121
122 /**********
123  * Action *
124  **********/
125 class NetworkCm02Action : virtual public Action {
126 public:
127   NetworkCm02Action(ModelPtr model, double cost, bool failed)
128  : Action(model, cost, failed) {};
129   double m_latency;
130   double m_latCurrent;
131   double m_weight;
132   double m_rate;
133   const char* p_senderLinkName;
134   double m_senderGap;
135   double m_senderSize;
136   xbt_fifo_item_t p_senderFifoItem;
137 #ifdef HAVE_LATENCY_BOUND_TRACKING
138   int m_latencyLimited;
139 #endif
140
141 };
142
143 class NetworkCm02ActionLmm : public ActionLmm, public NetworkCm02Action {
144 public:
145   NetworkCm02ActionLmm(ModelPtr model, double cost, bool failed)
146  : Action(model, cost, failed),
147    ActionLmm(model, cost, failed),
148    NetworkCm02Action(model, cost, failed) {};
149   void updateRemainingLazy(double now);
150   void recycle();
151 };
152
153 #endif /* SURF_MODEL_NETWORK_H_ */