Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1fe0b9698f0ff92047af0a6a84230964418b8488
[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 /* 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_crosstraffic;
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
64 void surf_action_lmm_update_index_heap(void *action, int i); /* callback for heap management shared by cpu and net models */
65 void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action,
66     double key, enum heap_action_type hat);
67 void surf_action_lmm_heap_remove(xbt_heap_t heap,surf_action_lmm_t action);
68
69
70 FILE *surf_fopen(const char *name, const char *mode);
71
72 extern tmgr_history_t history;
73 extern xbt_dynar_t surf_path;
74
75 void surf_config_init(int *argc, char **argv);
76 void surf_config_finalize(void);
77 void surf_config(const char *name, va_list pa);
78
79 void net_action_recycle(surf_action_t action);
80 double net_action_get_remains(surf_action_t action);
81 #ifdef HAVE_LATENCY_BOUND_TRACKING
82 int net_get_link_latency_limited(surf_action_t action);
83 #endif
84 void net_action_set_max_duration(surf_action_t action, double duration);
85 /*
86  * Returns the initial path. On Windows the initial path is
87  * the current directory for the current process in the other
88  * case the function returns "./" that represents the current
89  * directory on Unix/Linux platforms.
90  */
91 const char *__surf_get_initial_path(void);
92
93 /* The __surf_is_absolute_file_path() returns 1 if
94  * file_path is a absolute file path, in the other
95  * case the function returns 0.
96  */
97 int __surf_is_absolute_file_path(const char *file_path);
98
99 typedef struct s_as *AS_t;
100 typedef struct s_routing_edge {
101   AS_t rc_component;
102   e_surf_network_element_type_t rc_type;
103   int id;
104   char *name;
105 } s_network_element_t;
106
107 /*
108  * Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
109  */
110 typedef struct s_onelink {
111   sg_routing_edge_t src;
112   sg_routing_edge_t dst;
113   void *link_ptr;
114 } s_onelink_t, *onelink_t;
115
116 /**
117  * Routing logic
118  */
119
120 typedef struct s_model_type {
121   const char *name;
122   const char *desc;
123   AS_t (*create) ();
124   void (*end) (AS_t as);
125 } s_routing_model_description_t, *routing_model_description_t;
126
127 typedef struct s_route {
128   xbt_dynar_t link_list;
129   sg_routing_edge_t src_gateway;
130   sg_routing_edge_t dst_gateway;
131 } s_route_t, *route_t;
132
133 /* This enum used in the routing structure helps knowing in which situation we are. */
134 typedef enum {
135   SURF_ROUTING_NULL = 0,   /**< Undefined type                                   */
136   SURF_ROUTING_BASE,       /**< Base case: use simple link lists for routing     */
137   SURF_ROUTING_RECURSIVE   /**< Recursive case: also return gateway informations */
138 } e_surf_routing_hierarchy_t;
139
140 typedef struct s_as {
141   xbt_dynar_t index_network_elm;
142   xbt_dict_t bypassRoutes;              /* store bypass routes */
143   routing_model_description_t model_desc;
144   e_surf_routing_hierarchy_t hierarchy;
145   char *name;
146   struct s_as *routing_father;
147   xbt_dict_t routing_sons;
148   sg_routing_edge_t net_elem;
149   xbt_dynar_t link_up_down_list;
150
151   void (*get_route_and_latency) (AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, route_t into, double *latency);
152
153   xbt_dynar_t(*get_onelink_routes) (AS_t as);
154   route_t(*get_bypass_route) (AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, double *lat);
155   void (*finalize) (AS_t as);
156
157
158   /* The parser calls the following functions to inform the routing models
159    * that a new element is added to the AS currently built.
160    *
161    * Of course, only the routing model of this AS is informed, not every ones */
162   int (*parse_PU) (AS_t as, sg_routing_edge_t elm); /* A host or a router, whatever */
163   int (*parse_AS) (AS_t as, sg_routing_edge_t elm);
164   void (*parse_route) (AS_t as, const char *src,
165                      const char *dst, route_t route);
166   void (*parse_ASroute) (AS_t as, const char *src,
167                        const char *dst, route_t route);
168   void (*parse_bypassroute) (AS_t as, const char *src,
169                            const char *dst, route_t e_route);
170 } s_as_t;
171
172 struct s_routing_platf {
173   AS_t root;
174   void *loopback;
175   xbt_dynar_t last_route;
176   xbt_dynar_t(*get_onelink_routes) (void);
177 };
178
179 XBT_PUBLIC(void) routing_model_create(void *loopback);
180 XBT_PUBLIC(void) routing_exit(void);
181 XBT_PUBLIC(void) storage_register_callbacks(void);
182 XBT_PUBLIC(void) routing_register_callbacks(void);
183 XBT_PUBLIC(void) generic_free_route(route_t route); // FIXME rename to routing_route_free
184  // FIXME: make previous function private to routing again?
185
186
187 XBT_PUBLIC(void) routing_get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
188                               xbt_dynar_t * route, double *latency);
189
190 /**
191  * Resource protected methods
192  */
193 static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource);
194
195 XBT_PUBLIC(void) surfxml_bufferstack_push(int new);
196 XBT_PUBLIC(void) surfxml_bufferstack_pop(int new);
197
198 XBT_PUBLIC_DATA(int) surfxml_bufferstack_size;
199
200 #endif                          /* _SURF_SURF_PRIVATE_H */