Logo AND Algorithmique Numérique Distribuée

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