Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill further globals
[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_private.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 /* user-visible parameters */
21 extern double sg_tcp_gamma;
22 extern double sg_sender_gap;
23 extern double sg_latency_factor;
24 extern double sg_bandwidth_factor;
25 extern double sg_weight_S_parameter;
26 extern int sg_maxmin_selective_update;
27 extern int sg_network_fullduplex;
28 #ifdef HAVE_GTNETS
29 extern double sg_gtnets_jitter;
30 extern int sg_gtnets_jitter_seed;
31 #endif
32
33
34 extern const char *surf_action_state_names[6];
35
36 typedef struct surf_model_private {
37   int (*resource_used) (void *resource_id);
38   /* Share the resources to the actions and return in how much time
39      the next action may terminate */
40   double (*share_resources) (double now);
41   /* Update the actions' state */
42   void (*update_actions_state) (double now, double delta);
43   void (*update_resource_state) (void *id, tmgr_trace_event_t event_type,
44                                  double value, double time);
45   void (*finalize) (void);
46 } s_surf_model_private_t;
47
48 double generic_maxmin_share_resources(xbt_swag_t running_actions,
49                                       size_t offset,
50                                       lmm_system_t sys,
51                                       void (*solve) (lmm_system_t));
52
53 /* Generic functions common to all models */
54 void surf_action_init(void);
55 void surf_action_exit(void);
56 e_surf_action_state_t surf_action_state_get(surf_action_t action);      /* cannot declare inline since we use a pointer to it */
57 double surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
58 double surf_action_get_finish_time(surf_action_t action);       /* cannot declare inline since we use a pointer to it */
59 void surf_action_free(surf_action_t * action);
60 void surf_action_state_set(surf_action_t action,
61                            e_surf_action_state_t state);
62 void surf_action_data_set(surf_action_t action, void *data);    /* cannot declare inline since we use a pointer to it */
63 FILE *surf_fopen(const char *name, const char *mode);
64
65 extern tmgr_history_t history;
66 extern xbt_dynar_t surf_path;
67
68 void surf_config_init(int *argc, char **argv);
69 void surf_config_finalize(void);
70 void surf_config(const char *name, va_list pa);
71
72 void net_action_recycle(surf_action_t action);
73 double net_action_get_remains(surf_action_t action);
74 #ifdef HAVE_LATENCY_BOUND_TRACKING
75 int net_get_link_latency_limited(surf_action_t action);
76 #endif
77 void net_action_set_max_duration(surf_action_t action, double duration);
78 /*
79  * Returns the initial path. On Windows the initial path is
80  * the current directory for the current process in the other
81  * case the function returns "./" that represents the current
82  * directory on Unix/Linux platforms.
83  */
84 const char *__surf_get_initial_path(void);
85
86 /* The __surf_is_absolute_file_path() returns 1 if
87  * file_path is a absolute file path, in the other
88  * case the function returns 0.
89  */
90 int __surf_is_absolute_file_path(const char *file_path);
91
92 /*
93  * One link routing list
94  */
95 typedef struct s_onelink {
96   char *src;
97   char *dst;
98   void *link_ptr;
99 } s_onelink_t, *onelink_t;
100
101 /**
102  * Routing logic
103  */
104 typedef struct s_as *AS_t;
105
106 typedef struct s_model_type {
107   const char *name;
108   const char *desc;
109   AS_t (*create) ();
110   void (*end) (AS_t as);
111 } s_routing_model_description_t, *routing_model_description_t;
112
113 typedef struct s_route {
114   xbt_dynar_t link_list;
115 } s_route_t, *route_t;
116
117 typedef struct s_route_extended {
118   s_route_t generic_route;
119   char *src_gateway;
120   char *dst_gateway;
121 } s_route_extended_t, *route_extended_t;
122
123 /* This enum used in the routing structure helps knowing in which situation we are. */
124 typedef enum {
125   SURF_ROUTING_NULL = 0,   /**< Undefined type                                   */
126   SURF_ROUTING_BASE,       /**< Base case: use simple link lists for routing     */
127   SURF_ROUTING_RECURSIVE   /**< Recursive case: also return gateway informations */
128 } e_surf_routing_hierarchy_t;
129
130 typedef struct s_as {
131   xbt_dict_t to_index;                  /* char* -> network_element_t */
132   xbt_dict_t bypassRoutes;              /* store bypass routes */
133   routing_model_description_t routing;
134   e_surf_routing_hierarchy_t hierarchy;
135   char *name;
136   struct s_as *routing_father;
137   xbt_dict_t routing_sons;
138   route_extended_t(*get_route) (AS_t as, const char *src,
139                                 const char *dst);
140   double(*get_latency) (AS_t as, const char *src,
141                         const char *dst, route_extended_t e_route);
142   xbt_dynar_t(*get_onelink_routes) (AS_t as);
143   e_surf_network_element_type_t(*get_network_element_type) (const char *name);
144   route_extended_t(*get_bypass_route) (AS_t as,
145                                        const char *src, const char *dst);
146   void (*finalize) (AS_t as);
147   /* The parser calls the following functions to inform the routing models
148    * that a new element is added to the AS currently built.
149    *
150    * Of course, only the routing model of this AS is informed, not every ones */
151   void (*parse_PU) (AS_t as, const char *name); /* A host or a router, whatever */
152   void (*parse_AS) (AS_t as, const char *name);
153   void (*parse_route) (AS_t as, const char *src,
154                      const char *dst, route_extended_t route);
155   void (*parse_ASroute) (AS_t as, const char *src,
156                        const char *dst, route_extended_t route);
157   void (*parse_bypassroute) (AS_t as, const char *src,
158                            const char *dst, route_extended_t e_route);
159 } s_as_t;
160
161 typedef struct s_network_element_info {
162   AS_t rc_component;
163   e_surf_network_element_type_t rc_type;
164 } s_network_element_info_t, *network_element_info_t;
165
166 typedef int *network_element_t;
167
168 struct s_routing_global {
169   AS_t root;
170   void *loopback;
171   size_t size_of_link;
172   xbt_dynar_t(*get_route) (const char *src, const char *dst);
173   xbt_dynar_t(*get_route_or_null) (const char *src, const char *dst);
174   xbt_dynar_t(*get_route_no_cleanup) (const char *src, const char *dst);
175   xbt_dynar_t(*get_onelink_routes) (void);
176   double (*get_latency) (const char *src, const char *dst);
177   void (*get_route_latency)(const char *src, const char *dst,
178                             xbt_dynar_t *route, double *latency, int cleanup);
179   e_surf_network_element_type_t(*get_network_element_type) (const char *name);
180   void (*finalize) (void);
181   xbt_dynar_t last_route;
182 };
183
184 XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback);
185 XBT_PUBLIC(void) routing_register_callbacks(void);
186
187 /**
188  * Resource protected methods
189  */
190 static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource);
191
192 XBT_PUBLIC(void) surfxml_bufferstack_push(int new);
193 XBT_PUBLIC(void) surfxml_bufferstack_pop(int new);
194
195 XBT_PUBLIC_DATA(int) surfxml_bufferstack_size;
196
197 #endif                          /* _SURF_SURF_PRIVATE_H */