Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
296fef3cd6b1d19ac90788adaf69996608febb33
[simgrid.git] / src / surf / surf_private.h
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef _SURF_SURF_PRIVATE_H
7 #define _SURF_SURF_PRIVATE_H
8
9 #include "surf/surf.h"
10 #include "surf/maxmin.h"
11 #include "surf/trace_mgr.h"
12 #include "xbt/log.h"
13 #include "surf/surfxml_parse.h"
14 #include "surf/random_mgr.h"
15 #include "instr/instr_private.h"
16 #include "surf/surfxml_parse_values.h"
17
18 #define NO_MAX_DURATION -1.0
19
20 typedef enum {
21   UM_FULL,
22   UM_LAZY,
23   UM_UNDEFINED
24 } e_UM_t;
25
26 /* user-visible parameters */
27 extern double sg_tcp_gamma;
28 extern double sg_sender_gap;
29 extern double sg_latency_factor;
30 extern double sg_bandwidth_factor;
31 extern double sg_weight_S_parameter;
32 extern int sg_maxmin_selective_update;
33 extern int sg_network_crosstraffic;
34 #ifdef HAVE_GTNETS
35 extern double sg_gtnets_jitter;
36 extern int sg_gtnets_jitter_seed;
37 #endif
38
39
40 extern const char *surf_action_state_names[6];
41
42 typedef struct surf_model_private {
43   int (*resource_used) (void *resource_id);
44   /* Share the resources to the actions and return in how much time
45      the next action may terminate */
46   double (*share_resources) (double now);
47   /* Update the actions' state */
48   void (*update_actions_state) (double now, double delta);
49   void (*update_resource_state) (void *id, tmgr_trace_event_t event_type,
50                                  double value, double time);
51   void (*finalize) (void);
52 } s_surf_model_private_t;
53
54 double generic_maxmin_share_resources(xbt_swag_t running_actions,
55                                       size_t offset,
56                                       lmm_system_t sys,
57                                       void (*solve) (lmm_system_t));
58
59 /* Generic functions common to all models */
60 void surf_action_init(void);
61 void surf_action_exit(void);
62 e_surf_action_state_t surf_action_state_get(surf_action_t action);      /* cannot declare inline since we use a pointer to it */
63 double surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
64 double surf_action_get_finish_time(surf_action_t action);       /* cannot declare inline since we use a pointer to it */
65 void surf_action_free(surf_action_t * action);
66 void surf_action_state_set(surf_action_t action,
67                            e_surf_action_state_t state);
68 void surf_action_data_set(surf_action_t action, void *data);    /* cannot declare inline since we use a pointer to it */
69
70 void surf_action_lmm_update_index_heap(void *action, int i); /* callback for heap management shared by cpu and net models */
71 void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action,
72     double key, enum heap_action_type hat);
73 void surf_action_lmm_heap_remove(xbt_heap_t heap,surf_action_lmm_t action);
74
75
76 FILE *surf_fopen(const char *name, const char *mode);
77
78 extern tmgr_history_t history;
79 extern xbt_dynar_t surf_path;
80
81 void surf_config_init(int *argc, char **argv);
82 void surf_config_finalize(void);
83 void surf_config(const char *name, va_list pa);
84
85 void net_action_recycle(surf_action_t action);
86 double net_action_get_remains(surf_action_t action);
87 #ifdef HAVE_LATENCY_BOUND_TRACKING
88 int net_get_link_latency_limited(surf_action_t action);
89 #endif
90 void net_action_set_max_duration(surf_action_t action, double duration);
91 /*
92  * Returns the initial path. On Windows the initial path is
93  * the current directory for the current process in the other
94  * case the function returns "./" that represents the current
95  * directory on Unix/Linux platforms.
96  */
97 const char *__surf_get_initial_path(void);
98
99 /* The __surf_is_absolute_file_path() returns 1 if
100  * file_path is a absolute file path, in the other
101  * case the function returns 0.
102  */
103 int __surf_is_absolute_file_path(const char *file_path);
104
105 /*
106  * Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
107  */
108 typedef struct s_onelink {
109   char *src;
110   char *dst;
111   void *link_ptr;
112 } s_onelink_t, *onelink_t;
113
114 /**
115  * Routing logic
116  */
117 typedef struct s_as *AS_t;
118
119 typedef struct s_model_type {
120   const char *name;
121   const char *desc;
122   AS_t (*create) ();
123   void (*end) (AS_t as);
124 } s_routing_model_description_t, *routing_model_description_t;
125
126 typedef struct s_route {
127   xbt_dynar_t link_list;
128   char *src_gateway;
129   char *dst_gateway;
130 } s_route_t, *route_t;
131
132 /* This enum used in the routing structure helps knowing in which situation we are. */
133 typedef enum {
134   SURF_ROUTING_NULL = 0,   /**< Undefined type                                   */
135   SURF_ROUTING_BASE,       /**< Base case: use simple link lists for routing     */
136   SURF_ROUTING_RECURSIVE   /**< Recursive case: also return gateway informations */
137 } e_surf_routing_hierarchy_t;
138
139 typedef struct s_as {
140   xbt_dict_t to_index;                  /* char* -> network_element_t */
141   xbt_dict_t bypassRoutes;              /* store bypass routes */
142   routing_model_description_t model_desc;
143   e_surf_routing_hierarchy_t hierarchy;
144   char *name;
145   struct s_as *routing_father;
146   xbt_dict_t routing_sons;
147
148   void (*get_route_and_latency) (AS_t as, const char *src, const char *dst, route_t into, double *latency);
149
150   xbt_dynar_t(*get_onelink_routes) (AS_t as);
151   route_t(*get_bypass_route) (AS_t as, const char *src, const char *dst);
152   void (*finalize) (AS_t as);
153
154
155   /* The parser calls the following functions to inform the routing models
156    * that a new element is added to the AS currently built.
157    *
158    * Of course, only the routing model of this AS is informed, not every ones */
159   void (*parse_PU) (AS_t as, const char *name); /* A host or a router, whatever */
160   void (*parse_AS) (AS_t as, const char *name);
161   void (*parse_route) (AS_t as, const char *src,
162                      const char *dst, route_t route);
163   void (*parse_ASroute) (AS_t as, const char *src,
164                        const char *dst, route_t route);
165   void (*parse_bypassroute) (AS_t as, const char *src,
166                            const char *dst, route_t e_route);
167 } s_as_t;
168
169 typedef struct s_network_element_info {
170   AS_t rc_component;
171   e_surf_network_element_type_t rc_type;
172   int id;
173   char *name;
174 } s_network_element_info_t, *network_element_info_t;
175
176 typedef int *network_element_t;
177
178 struct s_routing_global {
179   AS_t root;
180   void *loopback;
181   size_t size_of_link;
182   xbt_dynar_t last_route;
183   xbt_dynar_t(*get_onelink_routes) (void);
184 };
185
186 XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback);
187 XBT_PUBLIC(void) routing_exit(void);
188 XBT_PUBLIC(void) routing_register_callbacks(void);
189 XBT_PUBLIC(void) generic_free_route(route_t route); // FIXME rename to routing_route_free
190  // FIXME: make previous function private to routing again?
191
192
193 XBT_PUBLIC(void) routing_get_route_and_latency(const char *src, const char *dst,
194                               xbt_dynar_t * route, double *latency);
195
196 /**
197  * Resource protected methods
198  */
199 static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource);
200
201 XBT_PUBLIC(void) surfxml_bufferstack_push(int new);
202 XBT_PUBLIC(void) surfxml_bufferstack_pop(int new);
203
204 XBT_PUBLIC_DATA(int) surfxml_bufferstack_size;
205
206 #endif                          /* _SURF_SURF_PRIVATE_H */