Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Starting the network module.
[simgrid.git] / src / surf / network.c
1 /* Authors: Arnaud Legrand                                                  */
2
3 /* This program is free software; you can redistribute it and/or modify it
4    under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "network_private.h"
7 #include "xbt/dict.h"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(network, surf ,"Logging specific to the SURF network module");
10
11 surf_network_resource_t surf_network_resource = NULL;
12
13 static xbt_dict_t network_set = NULL;
14
15
16 static void *route_new(const char *src, const char* dst)
17 {
18   return NULL;
19 }
20
21 /*  
22    Semantic:  name       scale     initial     power     initial     state
23                                     power      trace      state      trace
24    
25    Token:   TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD TOKEN_WORD
26    Type:     string      float      float      string     ON/OFF     string
27 */
28
29 static void parse_route(void)
30 {
31   route_new(NULL,NULL);
32 }
33
34 static void parse_file(const char *file)
35 {
36   e_surf_token_t token;
37
38   find_section(file,"NETWORK");
39
40   while(1) {
41     token=surf_parse();
42
43     if(token==TOKEN_END_SECTION) break;
44     if(token==TOKEN_NEWLINE) continue;
45     
46     if(token==TOKEN_WORD) parse_route();
47     else {CRITICAL1("Parse error line %d\n",line_pos);xbt_abort();}
48   }
49
50   close_section("NETWORK");  
51 }
52
53 static void *name_service(const char *name)
54 {
55   return NULL;
56 }
57
58 static const char *get_resource_name(void *resource_id)
59 {
60   return NULL;
61 }
62
63 static int resource_used(void *resource_id)
64 {
65   return 0;
66 }
67
68 static void action_free(surf_action_t action)
69 {
70   return;
71 }
72
73 static void action_cancel(surf_action_t action)
74 {
75   return;
76 }
77
78 static void action_recycle(surf_action_t action)
79 {
80   return;
81 }
82
83 static void action_change_state(surf_action_t action, e_surf_action_state_t state)
84 {
85   return;
86 }
87
88 static xbt_heap_float_t share_resources(xbt_heap_float_t now)
89 {
90   return -1.0;
91 }
92
93 static void update_actions_state(xbt_heap_float_t now,
94                                  xbt_heap_float_t delta)
95 {
96   return;
97 }
98
99 static void update_resource_state(void *id,
100                                   tmgr_trace_event_t event_type, 
101                                   xbt_maxmin_float_t value)
102 {
103   return;
104 }
105
106 static surf_action_t communicate(void *src, void *dst, xbt_maxmin_float_t size)
107 {
108   return NULL;
109 }
110
111 static void finalize(void)
112 {
113 }
114
115 static void surf_network_resource_init_internal(void)
116 {
117   s_surf_action_t action;
118
119   surf_network_resource = xbt_new0(s_surf_network_resource_t,1);
120   
121   surf_network_resource->common_private = xbt_new0(s_surf_resource_private_t,1);
122   surf_network_resource->common_public = xbt_new0(s_surf_resource_public_t,1);
123 /*   surf_network_resource->extension_private = xbt_new0(s_surf_network_resource_extension_private_t,1); */
124   surf_network_resource->extension_public = xbt_new0(s_surf_network_resource_extension_public_t,1);
125
126   surf_network_resource->common_public->states.ready_action_set=
127     xbt_swag_new(xbt_swag_offset(action,state_hookup));
128   surf_network_resource->common_public->states.running_action_set=
129     xbt_swag_new(xbt_swag_offset(action,state_hookup));
130   surf_network_resource->common_public->states.failed_action_set=
131     xbt_swag_new(xbt_swag_offset(action,state_hookup));
132   surf_network_resource->common_public->states.done_action_set=
133     xbt_swag_new(xbt_swag_offset(action,state_hookup));
134
135   surf_network_resource->common_public->name_service = name_service;
136   surf_network_resource->common_public->get_resource_name = get_resource_name;
137   surf_network_resource->common_public->resource_used = resource_used;
138   surf_network_resource->common_public->action_get_state=surf_action_get_state;
139   surf_network_resource->common_public->action_free = action_free;
140   surf_network_resource->common_public->action_cancel = action_cancel;
141   surf_network_resource->common_public->action_recycle = action_recycle;
142   surf_network_resource->common_public->action_change_state = action_change_state;
143
144   surf_network_resource->common_private->share_resources = share_resources;
145   surf_network_resource->common_private->update_actions_state = update_actions_state;
146   surf_network_resource->common_private->update_resource_state = update_resource_state;
147   surf_network_resource->common_private->finalize = finalize;
148
149   surf_network_resource->extension_public->communicate = communicate;
150
151   network_set = xbt_dict_new();
152
153   xbt_assert0(maxmin_system,"surf_init has to be called first!");
154 }
155
156 void surf_network_resource_init(const char* filename)
157 {
158   surf_network_resource_init_internal();
159   parse_file(filename);
160   xbt_dynar_push(resource_list, &surf_network_resource);
161 }