Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Resolve memory leaks
[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         lmm_system_free(p_maxminSystem);
53         if (p_actionHeap)
54           xbt_heap_free(p_actionHeap);
55         if (p_modifiedSet)
56           xbt_swag_free(p_modifiedSet);
57   }
58   //FIXME:NetworkCm02LinkPtr createResource(string name);
59   NetworkCm02LinkLmmPtr createResource(const char *name,
60                                    double bw_initial,
61                                    tmgr_trace_t bw_trace,
62                                    double lat_initial,
63                                    tmgr_trace_t lat_trace,
64                                    e_surf_resource_state_t state_initial,
65                                    tmgr_trace_t state_trace,
66                                    e_surf_link_sharing_policy_t policy,
67                                    xbt_dict_t properties);
68   void updateActionsStateLazy(double now, double delta);
69   virtual void gapAppend(double /*size*/, const NetworkCm02LinkLmmPtr /*link*/, NetworkCm02ActionLmmPtr /*action*/) {};
70   virtual ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
71                                            double size, double rate);
72   xbt_dynar_t getRoute(RoutingEdgePtr src, RoutingEdgePtr dst); //FIXME: kill field? That is done by the routing nowadays
73   //FIXME: virtual void addTraces() =0;
74   void (*f_networkSolve)(lmm_system_t);
75   virtual double latencyFactor(double size);
76   virtual double bandwidthFactor(double size);
77   virtual double bandwidthConstraint(double rate, double bound, double size);
78   bool m_haveGap;
79 };
80
81 /************
82  * Resource *
83  ************/
84
85 class NetworkCm02Link : virtual public Resource {
86 public:
87   NetworkCm02Link() : p_latEvent(NULL) {};
88   NetworkCm02Link(NetworkCm02ModelPtr model, const char* name, xbt_dict_t properties)
89     : Resource(model, name, properties), p_latEvent(NULL) {};
90   virtual double getBandwidth()=0;
91   virtual double getLatency();
92   virtual bool isShared()=0;
93   /* Using this object with the public part of
94     model does not make sense */
95   double m_latCurrent;
96   tmgr_trace_event_t p_latEvent;
97 };
98
99 class NetworkCm02LinkLmm : public ResourceLmm, public NetworkCm02Link {
100 public:
101   NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char* name, xbt_dict_t properties)
102    : ResourceLmm(), NetworkCm02Link(model, name, properties) {};
103   NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
104                                    lmm_system_t system,
105                                    double constraint_value,
106                                    tmgr_history_t history,
107                                    e_surf_resource_state_t state_init,
108                                    tmgr_trace_t state_trace,
109                                    double metric_peak,
110                                    tmgr_trace_t metric_trace,
111                                    double lat_initial,
112                                    tmgr_trace_t lat_trace,
113                                e_surf_link_sharing_policy_t policy);
114   bool isShared();
115   bool isUsed();
116   double getBandwidth();
117   void updateState(tmgr_trace_event_t event_type, double value, double date);
118 };
119
120
121 /**********
122  * Action *
123  **********/
124 class NetworkCm02Action : virtual public Action {
125 public:
126   NetworkCm02Action(ModelPtr model, double cost, bool failed)
127  : Action(model, cost, failed) {};
128   double m_latency;
129   double m_latCurrent;
130   double m_weight;
131   double m_rate;
132   const char* p_senderLinkName;
133   double m_senderGap;
134   double m_senderSize;
135   xbt_fifo_item_t p_senderFifoItem;
136 #ifdef HAVE_LATENCY_BOUND_TRACKING
137   int m_latencyLimited;
138 #endif
139
140 };
141
142 class NetworkCm02ActionLmm : public ActionLmm, public NetworkCm02Action {
143 public:
144   NetworkCm02ActionLmm(ModelPtr model, double cost, bool failed)
145  : Action(model, cost, failed),
146    ActionLmm(model, cost, failed),
147    NetworkCm02Action(model, cost, failed) {};
148   void updateRemainingLazy(double now);
149   void recycle();
150 };
151
152 #endif /* SURF_MODEL_NETWORK_H_ */