Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merging tracing changes
[simgrid.git] / src / bindings / lua / lua_console.c
1 /* SimGrid Lua Console                                                    */
2
3 /* Copyright (c) 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "simgrid_lua.h"
10 #include <string.h>
11 #include <ctype.h>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_console, bindings, "Lua Bindings");
14
15
16 //AS List
17 static xbt_dynar_t as_list_d;
18
19 /*
20  * Initialize platform model routing
21  */
22
23 static void create_AS(const char *id, const char *mode)
24 {
25   surf_AS_new(id, mode);
26 }
27
28 /**
29  * create host resource via CPU model [for MSG]
30  */
31
32 static void create_host(const char *id, double power_peak, double power_sc,
33                         const char *power_tr,int core,int state_init,
34                         const char *state_tr,xbt_dict_t properties)
35 {
36   double power_scale = 1.0;
37   int core_nb = 1; //default value
38   tmgr_trace_t power_trace = NULL;
39   e_surf_resource_state_t state_initial;
40   tmgr_trace_t state_trace;
41   if (power_sc)                 // !=0
42     power_scale = power_sc;
43   if (core)
44           core_nb = core; //default value
45   if (state_init == -1)
46     state_initial = SURF_RESOURCE_OFF;
47   else
48     state_initial = SURF_RESOURCE_ON;
49   if (power_tr)
50     power_trace = tmgr_trace_new(power_tr);
51   else
52     power_trace = tmgr_trace_new("");
53   if (state_tr)
54     state_trace = tmgr_trace_new(state_tr);
55   else
56     state_trace = tmgr_trace_new("");
57
58   surf_host_create_resource(xbt_strdup(id), power_peak, power_scale,
59                             power_trace, core_nb, state_initial, state_trace,
60                             properties);
61 }
62
63 /**
64  * create link resource via network model
65  */
66 static void create_link(const char *name,
67                         double bw_initial, const char *trace,
68                         double lat_initial, const char *latency_trace,
69                         int state_init, const char *state_trace,
70                         int policy)
71 {
72   tmgr_trace_t bw_trace;
73   tmgr_trace_t lat_trace;
74   e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON;
75   e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
76   tmgr_trace_t st_trace;
77   if (trace)
78     bw_trace = tmgr_trace_new(trace);
79   else
80     bw_trace = tmgr_trace_new("");
81
82   if (latency_trace)
83     lat_trace = tmgr_trace_new(latency_trace);
84   else
85     lat_trace = tmgr_trace_new("");
86
87   if (state_trace)
88     st_trace = tmgr_trace_new(state_trace);
89   else
90     st_trace = tmgr_trace_new("");
91
92   if (state_init == -1)
93     state_initial_link = SURF_RESOURCE_OFF;
94   if (policy == -1)
95     policy_initial_link = SURF_LINK_FATPIPE;
96
97   surf_link_create_resource(xbt_strdup(name), bw_initial, bw_trace,
98                             lat_initial, lat_trace, state_initial_link,
99                             st_trace, policy_initial_link, xbt_dict_new());
100 }
101
102 /*
103  *create host resource via workstation_ptask_L07 model [for SimDag]
104  */
105 static void create_host_wsL07(const char *id, double power_peak,
106                               double power_sc, const char *power_tr,
107                               int state_init, const char *state_tr)
108 {
109   double power_scale = 1.0;
110   tmgr_trace_t power_trace = NULL;
111   e_surf_resource_state_t state_initial;
112   tmgr_trace_t state_trace;
113   if (power_sc)                 // !=0
114     power_scale = power_sc;
115   if (state_init == -1)
116     state_initial = SURF_RESOURCE_OFF;
117   else
118     state_initial = SURF_RESOURCE_ON;
119   if (power_tr)
120     power_trace = tmgr_trace_new(power_tr);
121   else
122     power_trace = tmgr_trace_new("");
123   if (state_tr)
124     state_trace = tmgr_trace_new(state_tr);
125   else
126     state_trace = tmgr_trace_new("");
127
128   surf_wsL07_host_create_resource(xbt_strdup(id), power_peak, power_scale,
129                                   power_trace, state_initial, state_trace,
130                                   current_property_set);
131   current_property_set = NULL;
132 }
133
134 /**
135  * create link resource via workstation_ptask_L07 model [for SimDag]
136  */
137
138 static void create_link_wsL07(const char *name,
139                               double bw_initial, const char *trace,
140                               double lat_initial,
141                               const char *latency_trace, int state_init,
142                               const char *state_trace, int policy)
143 {
144   tmgr_trace_t bw_trace;
145   tmgr_trace_t lat_trace;
146   e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON;
147   e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED;
148   tmgr_trace_t st_trace;
149   if (trace)
150     bw_trace = tmgr_trace_new(trace);
151   else
152     bw_trace = tmgr_trace_new("");
153
154   if (latency_trace)
155     lat_trace = tmgr_trace_new(latency_trace);
156   else
157     lat_trace = tmgr_trace_new("");
158
159   if (state_trace)
160     st_trace = tmgr_trace_new(state_trace);
161   else
162     st_trace = tmgr_trace_new("");
163
164   if (state_init == -1)
165     state_initial_link = SURF_RESOURCE_OFF;
166   if (policy == -1)
167     policy_initial_link = SURF_LINK_FATPIPE;
168
169   surf_wsL07_link_create_resource(xbt_strdup(name), bw_initial, bw_trace,
170                                   lat_initial, lat_trace,
171                                   state_initial_link, st_trace,
172                                   policy_initial_link, xbt_dict_new());
173 }
174
175
176 /*
177  * Append new AS to the Platform
178  */
179
180 static int AS_new(lua_State * L)
181 {
182
183    if (xbt_dynar_is_empty(as_list_d))
184             as_list_d = xbt_dynar_new(sizeof(p_AS_attr), &xbt_free_ref);
185
186   p_AS_attr AS;
187   const char *id;
188   const char *mode;
189   if (lua_istable(L, 1)) {
190     lua_pushstring(L, "id");
191     lua_gettable(L, -2);
192     id = lua_tostring(L, -1);
193     lua_pop(L, 1);
194
195     lua_pushstring(L, "mode");
196     lua_gettable(L, -2);
197     mode = lua_tostring(L, -1);
198     lua_pop(L, 1);
199   } else {
200     XBT_ERROR
201         ("Bad Arguments to AS.new, Should be a table with named arguments");
202     return -1;
203   }
204   AS = malloc(sizeof(AS_attr));
205   AS->id = id;
206   AS->mode = mode;
207   AS->host_list_d = xbt_dynar_new(sizeof(p_host_attr),&xbt_free_ref);
208   AS->link_list_d = xbt_dynar_new(sizeof(p_link_attr),&xbt_free_ref);
209   AS->route_list_d = xbt_dynar_new(sizeof(p_route_attr),&xbt_free_ref);
210   AS->router_list_d = xbt_dynar_new(sizeof(p_router_attr),&xbt_free_ref);
211   AS->sub_as_list_id = xbt_dynar_new(sizeof(p_AS_attr),&xbt_free_ref);
212   xbt_dynar_push(as_list_d, &AS);
213
214   return 0;
215 }
216
217 /**
218  * add sub AS to the Parent AS
219  */
220 static int AS_add(lua_State *L)
221 {
222         unsigned int i;
223         p_AS_attr AS;
224         p_AS_attr super_as,p_as;
225         const char *super_AS_id;
226         const char *sub_AS_id = NULL;
227         const char *sub_AS_routing= NULL;
228         if(lua_istable(L, -1))
229         {
230                 lua_pushstring(L, "AS");
231                 lua_gettable(L, -2);
232                 super_AS_id = lua_tostring(L, -1);
233                 lua_pop(L,1);
234
235                 lua_pushstring(L, "id");
236                 lua_gettable(L, -2);
237                 sub_AS_id = lua_tostring(L, -1);
238                 lua_pop(L,1);
239
240         }
241
242         xbt_dynar_foreach(as_list_d, i, p_as){
243                   if (p_as->id == super_AS_id){
244                           super_as = p_as;
245                           break;
246                   }
247         }
248         AS = malloc(sizeof(AS_attr));
249         AS->id = sub_AS_id;
250         AS->mode = sub_AS_routing;
251         AS->host_list_d = xbt_dynar_new(sizeof(p_host_attr),&xbt_free_ref);
252         AS->link_list_d = xbt_dynar_new(sizeof(p_link_attr),&xbt_free_ref);
253         AS->route_list_d = xbt_dynar_new(sizeof(p_route_attr),&xbt_free_ref);
254         AS->sub_as_list_id = xbt_dynar_new(sizeof(p_AS_attr),&xbt_free_ref);
255         xbt_dynar_push(super_as->sub_as_list_id, &AS);
256
257         return 0;
258 }
259
260
261 /*
262  * add new host to platform hosts list
263  */
264 static int Host_new(lua_State * L)
265 {
266   p_host_attr host;
267   unsigned int i;
268   p_AS_attr p_as,current_as = NULL;
269   const char *AS_id;
270   const char *id;
271   const char *power_trace;
272   const char *state_trace;
273   double power, power_scale;
274   int state_initial,core;
275   //get values from the table passed as argument
276   if (lua_istable(L, -1)) {
277         // get AS id
278         lua_pushstring(L, "AS");
279         lua_gettable(L, -2);
280         AS_id = lua_tostring(L, -1);
281         lua_pop(L,1);
282
283     // get Id Value
284     lua_pushstring(L, "id");
285     lua_gettable(L, -2);
286     id = lua_tostring(L, -1);
287     lua_pop(L, 1);
288
289     // get power value
290     lua_pushstring(L, "power");
291     lua_gettable(L, -2);
292     power = lua_tonumber(L, -1);
293     lua_pop(L, 1);
294
295     //get power_scale
296     lua_pushstring(L, "power_scale");
297     lua_gettable(L, -2);
298     power_scale = lua_tonumber(L, -1);
299     lua_pop(L, 1);
300
301     //get power_trace
302     lua_pushstring(L, "power_trace");
303     lua_gettable(L, -2);
304     power_trace = lua_tostring(L, -1);
305     lua_pop(L, 1);
306
307     lua_pushstring(L, "core");
308     lua_gettable(L, -2);
309     core = lua_tonumber(L, -1);
310     lua_pop(L, 1);
311
312     //get state initial
313     lua_pushstring(L, "state_initial");
314     lua_gettable(L, -2);
315     state_initial = lua_tonumber(L, -1);
316     lua_pop(L, 1);
317
318     //get trace state
319     lua_pushstring(L, "state_trace");
320     lua_gettable(L, -2);
321     state_trace = lua_tostring(L, -1);
322     lua_pop(L, 1);
323
324   } else {
325     XBT_ERROR
326         ("Bad Arguments to create host, Should be a table with named arguments");
327     return -1;
328   }
329   xbt_dynar_foreach(as_list_d, i, p_as){
330           if (p_as->id == AS_id){
331                   current_as = p_as;
332                   break;
333           }
334   }
335
336   if (!current_as)
337   {
338           XBT_ERROR("No AS_id :%s found",AS_id);
339           return -2;
340   }
341
342   host = malloc(sizeof(host_attr));
343   host->id = id;
344   host->power_peak = power;
345   host->power_scale = power_scale;
346   host->power_trace = power_trace;
347   host->core = core;
348   host->state_initial = state_initial;
349   host->state_trace = state_trace;
350   host->function = NULL;
351   host->properties = xbt_dict_new();
352   xbt_dynar_push(current_as->host_list_d, &host);
353
354   return 0;
355 }
356
357 /**
358  * add link to AS links list
359  */
360 static int Link_new(lua_State * L)      // (id,bandwidth,latency)
361 {
362   const char *AS_id;
363   unsigned int i;
364   p_AS_attr p_as,current_as = NULL;
365   const char* id;
366   double bandwidth, latency;
367   const char *bandwidth_trace;
368   const char *latency_trace;
369   const char *state_trace;
370   int state_initial, policy;
371
372   //get values from the table passed as argument
373   if (lua_istable(L, -1)) {
374
375         //get AS id
376         lua_pushstring(L, "AS");
377         lua_gettable(L, -2);
378         AS_id = lua_tostring(L, -1);
379         lua_pop(L, 1);
380
381     // get Id Value
382     lua_pushstring(L, "id");
383     lua_gettable(L, -2);
384     id = lua_tostring(L, -1);
385     lua_pop(L, 1);
386
387     // get bandwidth value
388     lua_pushstring(L, "bandwidth");
389     lua_gettable(L, -2);
390     bandwidth = lua_tonumber(L, -1);
391     lua_pop(L, 1);
392
393     //get latency value
394     lua_pushstring(L, "latency");
395     lua_gettable(L, -2);
396     latency = lua_tonumber(L, -1);
397     lua_pop(L, 1);
398
399     /*Optional Arguments  */
400
401     //get bandwidth_trace value
402     lua_pushstring(L, "bandwidth_trace");
403     lua_gettable(L, -2);
404     bandwidth_trace = lua_tostring(L, -1);
405     lua_pop(L, 1);
406
407     //get latency_trace value
408     lua_pushstring(L, "latency_trace");
409     lua_gettable(L, -2);
410     latency_trace = lua_tostring(L, -1);
411     lua_pop(L, 1);
412
413     //get state_trace value
414     lua_pushstring(L, "state_trace");
415     lua_gettable(L, -2);
416     state_trace = lua_tostring(L, -1);
417     lua_pop(L, 1);
418
419     //get state_initial value
420     lua_pushstring(L, "state_initial");
421     lua_gettable(L, -2);
422     state_initial = lua_tonumber(L, -1);
423     lua_pop(L, 1);
424
425     //get policy value
426     lua_pushstring(L, "policy");
427     lua_gettable(L, -2);
428     policy = lua_tonumber(L, -1);
429     lua_pop(L, 1);
430
431   } else {
432     XBT_ERROR
433         ("Bad Arguments to create link, Should be a table with named arguments");
434     return -1;
435   }
436   xbt_dynar_foreach(as_list_d, i, p_as){
437           if (p_as->id == AS_id){
438                   current_as = p_as;
439                   break;
440           }
441   }
442
443   if (!current_as)
444   {
445           XBT_ERROR("No AS_id :%s found",AS_id);
446           return -2;
447   }
448   p_link_attr link = malloc(sizeof(link_attr));
449   link->id = id;
450   link->bandwidth = bandwidth;
451   link->latency = latency;
452   link->bandwidth_trace = bandwidth_trace;
453   link->latency_trace = latency_trace;
454   link->state_trace = state_trace;
455   link->state_initial = state_initial;
456   link->policy = policy;
457   xbt_dynar_push(current_as->link_list_d, &link);
458
459   return 0;
460 }
461
462 /**
463  * add route to AS routes list
464  */
465 static int Route_new(lua_State * L)     // (src_id,dest_id,links_number,link_table)
466 {
467   const char* AS_id;
468   unsigned int i;
469   p_AS_attr p_as,current_as = NULL;
470   const char *links;
471   const char* link_id;
472   p_route_attr route = malloc(sizeof(route_attr));
473
474
475   if (!lua_istable(L, 4)) { // if Route.new is declared as an indexed table (FIXME : we check the third arg if it's not a table)
476
477          //get AS_id
478          lua_pushstring(L, "AS");
479          lua_gettable(L, -2);
480          AS_id = lua_tostring(L, -1);
481          lua_pop(L, 1);
482
483          xbt_dynar_foreach(as_list_d, i, p_as){
484           if (p_as->id == AS_id){
485                   current_as = p_as;
486                   break;
487           }
488          }
489
490          if (!current_as)
491          {
492           XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
493           return -2;
494          }
495          // get Source Value
496      lua_pushstring(L, "src");
497      lua_gettable(L, -2);
498      route->src_id = lua_tostring(L, -1);
499      lua_pop(L, 1);
500
501      // get Destination Value
502      lua_pushstring(L, "dest");
503      lua_gettable(L, -2);
504      route->dest_id = lua_tostring(L, -1);
505      lua_pop(L, 1);
506
507      // get Links Table (char* to be splited later)
508      lua_pushstring(L, "links");
509      lua_gettable(L, -2);
510      links = lua_tostring(L, -1);
511      lua_pop(L,1);
512
513      route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
514
515      char *tmp_links = xbt_strdup(links);
516      link_id = strtok(tmp_links,",");   //tmp_link = strtok((char*)links,",");
517      while(link_id != NULL)
518        {
519           xbt_dynar_push(route->links_id, &link_id);
520           link_id = strtok(NULL,","); //Alternatively, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.
521         }
522      xbt_dynar_push(current_as->route_list_d, &route);
523      return 0;
524       }
525   else { // Route.new is declared as a function
526          AS_id = luaL_checkstring(L, 1);
527          xbt_dynar_foreach(as_list_d, i, p_as){
528                   if (p_as->id == AS_id){
529                           current_as = p_as;
530                           break;
531                   }
532                  }
533
534          if (!current_as)
535          {
536                 XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
537                 return -2;
538          }
539      route->src_id = luaL_checkstring(L, 2);
540      route->dest_id = luaL_checkstring(L, 3);
541      route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
542      lua_pushnil(L);
543      while (lua_next(L, 4) != 0)
544                 {
545          link_id = lua_tostring(L, -1);
546          xbt_dynar_push(route->links_id, &link_id);
547          XBT_DEBUG("index = %f , Link_id = %s \n", lua_tonumber(L, -2),
548          lua_tostring(L, -1));
549          lua_pop(L, 1);
550         }
551     lua_pop(L, 1);
552     //add route to platform's route list
553     xbt_dynar_push(current_as->route_list_d, &route);
554     return 0;
555     }
556
557   return -1;
558 }
559 /**
560  * add Router to AS components
561  */
562 static int Router_new(lua_State* L)
563 {
564         p_router_attr router;
565         const char* AS_id;
566         unsigned int i;
567         p_AS_attr p_as,current_as = NULL;
568         const char* id;
569         if (lua_istable(L, -1)) {
570                 // get AS id
571                 lua_pushstring(L, "AS");
572                 lua_gettable(L, -2);
573                 AS_id = lua_tostring(L, -1);
574                 lua_pop(L,1);
575
576                 lua_pushstring(L, "id");
577                 lua_gettable(L, -2);
578                 id = lua_tostring(L, -1);
579                 lua_pop(L,1);
580         }
581         xbt_dynar_foreach(as_list_d, i, p_as){
582                   if (p_as->id == AS_id){
583                           current_as = p_as;
584                           break;
585                   }
586           }
587
588           if (!current_as)
589           {
590                   XBT_ERROR("No AS_id :%s found",AS_id);
591                   return -2;
592           }
593         router = malloc(sizeof(router_attr));
594         router->id = id;
595         xbt_dynar_push(current_as->router_list_d, &router);
596         return 0;
597
598 }
599
600 /**
601  * set function to process
602  */
603 static int Host_set_function(lua_State * L)     //(host,function,nb_args,list_args)
604 {
605         p_AS_attr p_as;
606         p_host_attr p_host;
607         unsigned int i,j;
608         const char *host_id ;
609         const char *function_id;
610         const char *args;
611         char * tmp_arg;
612
613    if (lua_istable(L, -1)) {
614          // get Host id
615          lua_pushstring(L, "host");
616          lua_gettable(L, -2);
617          host_id = lua_tostring(L, -1);
618          lua_pop(L, 1);
619          // get Function Name
620          lua_pushstring(L, "fct");
621          lua_gettable(L, -2);
622      function_id = lua_tostring(L, -1);
623      lua_pop(L, 1);
624      //get args
625      lua_pushstring(L,"args");
626      lua_gettable(L, -2);
627      args = lua_tostring(L,-1);
628      lua_pop(L, 1);
629    }
630    else {
631            XBT_ERROR("Bad Arguments to create link, Should be a table with named arguments");
632            return -1;
633    }
634
635   // look for the index of host in host_list for each AS
636    xbt_dynar_foreach(as_list_d, i, p_as)
637    {
638            xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
639                    if (p_host->id == host_id) {
640                            p_host->function = function_id;
641                            p_host->args_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
642                            // split & fill the args list
643                            tmp_arg = strtok((char*)args,",");
644                            while (tmp_arg != NULL) {
645                                    xbt_dynar_push(p_host->args_list, &tmp_arg);
646                                    tmp_arg = strtok(NULL,",");
647                            }
648                            return 0;
649                    }
650         }
651    }
652           XBT_ERROR("Host : %s Not Found !!", host_id);
653           return 1;
654
655 }
656
657 static int Host_set_property(lua_State* L)
658 {
659         p_AS_attr p_as;
660         p_host_attr p_host;
661         unsigned int i,j;
662         const char* host_id ="";
663         const char* prop_id = "";
664         const char* prop_value = "";
665         if (lua_istable(L, -1)) {
666                  // get Host id
667                  lua_pushstring(L, "host");
668                  lua_gettable(L, -2);
669                  host_id = lua_tostring(L, -1);
670                  lua_pop(L, 1);
671                  // get Function Name
672                  lua_pushstring(L, "prop_id");
673                  lua_gettable(L, -2);
674              prop_id = lua_tostring(L, -1);
675              lua_pop(L, 1);
676              //get args
677              lua_pushstring(L,"prop_value");
678              lua_gettable(L, -2);
679              prop_value = lua_tostring(L,-1);
680              lua_pop(L, 1);
681          }
682         xbt_dynar_foreach(as_list_d, i, p_as)
683            {
684                    xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
685                            if (p_host->id == host_id) {
686                                    xbt_dict_set(p_host->properties, prop_id, xbt_strdup(prop_value), free);
687                            }
688                    }
689       }
690         return 1;
691
692 }
693 /*
694  * surf parse bypass platform
695  * through CPU/network Models
696  */
697
698 static int surf_parse_bypass_platform()
699 {
700   unsigned int i,j;
701   p_AS_attr p_as;
702   p_host_attr p_host;
703   p_link_attr p_link;
704   p_route_attr p_route;
705
706
707   // Add AS
708   xbt_dynar_foreach(as_list_d, i,p_as)
709   {
710           create_AS(p_as->id, p_as->mode);
711           // add associated Hosts
712           xbt_dynar_foreach(p_as->host_list_d, j, p_host){
713                   create_host(p_host->id, p_host->power_peak, p_host->power_scale,
714                                   p_host->power_trace, p_host->core, p_host->state_initial,
715                                   p_host->state_trace, p_host->properties);
716
717
718                    //add to routing model host list
719                    surf_route_add_host((char *) p_host->id);
720           }
721           // add associated Links
722           xbt_dynar_foreach(p_as->link_list_d, j, p_link){
723                   create_link(p_link->id, p_link->bandwidth, p_link->bandwidth_trace,
724                                   p_link->latency, p_link->latency_trace,
725                                   p_link->state_initial, p_link->state_trace,
726                                   p_link->policy);
727           }
728           // add associated Routes
729           xbt_dynar_foreach(p_as->route_list_d, j, p_route){
730                   surf_routing_add_route((char *) p_route->src_id,
731                                              (char *) p_route->dest_id, p_route->links_id);
732           }
733
734           // Finalize AS
735           surf_AS_finalize(p_as->id);
736   }
737
738   // add traces
739   surf_add_host_traces();
740   surf_add_link_traces();
741
742   return 0;                     // must return 0 ?!!
743
744 }
745
746 /**
747  *
748  * surf parse bypass platform
749  * through workstation_ptask_L07 Model
750  */
751
752 static int surf_wsL07_parse_bypass_platform()
753 {
754   unsigned int i,j;
755   p_AS_attr p_as, p_sub_as;
756   p_host_attr p_host;
757   p_link_attr p_link;
758   p_route_attr p_route;
759
760   xbt_dynar_foreach(as_list_d, i, p_as)
761   {
762           // Init AS
763           create_AS(p_as->id, p_as->mode);
764
765           // add Sub AS
766
767           // Add Hosts
768           xbt_dynar_foreach(p_as->sub_as_list_id, j, p_sub_as) {
769                           //...
770           }
771           xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
772             create_host_wsL07(p_host->id, p_host->power_peak, p_host->power_scale,
773                               p_host->power_trace, p_host->state_initial,
774                               p_host->state_trace);
775             //add to routing model host list
776             surf_route_add_host((char *) p_host->id);
777           }
778           //add Links
779           xbt_dynar_foreach(p_as->link_list_d, j, p_link) {
780               create_link_wsL07(p_link->id, p_link->bandwidth,
781                                 p_link->bandwidth_trace, p_link->latency,
782                                 p_link->latency_trace, p_link->state_initial,
783                                 p_link->state_trace, p_link->policy);
784             }
785             // add route
786           xbt_dynar_foreach(p_as->route_list_d, j, p_route) {
787                 surf_routing_add_route((char *) p_route->src_id,
788                                        (char *) p_route->dest_id, p_route->links_id);
789               }
790           /* </AS> */
791           // Finalize AS
792           surf_AS_finalize(p_as->id);
793   }
794   // add traces
795   surf_wsL07_add_traces();
796   return 0;
797 }
798
799 /*
800  * surf parse bypass application for MSG Module
801  */
802 static int surf_parse_bypass_application()
803 {
804   unsigned int i,j;
805   p_AS_attr p_as;
806   p_host_attr p_host;
807   xbt_dynar_foreach(as_list_d, i, p_as)
808   {
809           xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
810                   if (p_host->function)
811                           MSG_set_function(p_host->id, p_host->function, p_host->args_list);
812           }
813   }
814   return 0;
815 }
816
817 /*
818  * Public Methods
819  */
820 int console_add_host(lua_State *L)
821 {
822         return Host_new(L);
823 }
824
825 int  console_add_link(lua_State *L)
826 {
827         return Link_new(L);
828 }
829
830 int console_add_route(lua_State *L)
831 {
832         return Route_new(L);
833 }
834
835 int console_add_AS(lua_State *L)
836 {
837         return AS_new(L);
838 }
839
840 int console_set_function(lua_State *L)
841 {
842         return Host_set_function(L);
843 }
844
845 int console_host_set_property(lua_State *L)
846 {
847         return Host_set_property(L);
848 }
849
850 int console_parse_platform()
851 {
852         return surf_parse_bypass_platform();
853 }
854
855 int  console_parse_application()
856 {
857         return surf_parse_bypass_application();
858 }
859
860 int console_parse_platform_wsL07()
861 {
862         return surf_wsL07_parse_bypass_platform();
863 }