Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3c709a5490042308433592cb0b6ab8dadf54ad45
[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  * set function to process
254  */
255 static int Host_set_function(lua_State * L)     //(host,function,nb_args,list_args)
256 {
257         p_AS_attr p_as;
258         p_host_attr p_host;
259         unsigned int i,j;
260         const char *host_id ;
261         const char *function_id;
262         const char *args;
263         char * tmp_arg;
264
265    if (lua_istable(L, -1)) {
266          // get Host id
267          lua_pushstring(L, "host");
268          lua_gettable(L, -2);
269          host_id = lua_tostring(L, -1);
270          lua_pop(L, 1);
271          // get Function Name
272          lua_pushstring(L, "fct");
273          lua_gettable(L, -2);
274      function_id = lua_tostring(L, -1);
275      lua_pop(L, 1);
276      //get args
277      lua_pushstring(L,"args");
278      lua_gettable(L, -2);
279      args = lua_tostring(L,-1);
280      lua_pop(L, 1);
281    }
282    else {
283            XBT_ERROR("Bad Arguments to create link, Should be a table with named arguments");
284            return -1;
285    }
286
287   // look for the index of host in host_list for each AS
288    xbt_dynar_foreach(as_list_d, i, p_as)
289    {
290            xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
291                    if (p_host->id == host_id) {
292                            p_host->function = function_id;
293                            p_host->args_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
294                            // split & fill the args list
295                            tmp_arg = strtok((char*)args,",");
296                            while (tmp_arg != NULL) {
297                                    xbt_dynar_push(p_host->args_list, &tmp_arg);
298                                    tmp_arg = strtok(NULL,",");
299                            }
300                            return 0;
301                    }
302         }
303    }
304           XBT_ERROR("Host : %s Not Found !!", host_id);
305           return 1;
306
307 }
308
309 static int Host_set_property(lua_State* L)
310 {
311         p_AS_attr p_as;
312         p_host_attr p_host;
313         unsigned int i,j;
314         const char* host_id ="";
315         const char* prop_id = "";
316         const char* prop_value = "";
317         if (lua_istable(L, -1)) {
318                  // get Host id
319                  lua_pushstring(L, "host");
320                  lua_gettable(L, -2);
321                  host_id = lua_tostring(L, -1);
322                  lua_pop(L, 1);
323                  // get Function Name
324                  lua_pushstring(L, "prop_id");
325                  lua_gettable(L, -2);
326              prop_id = lua_tostring(L, -1);
327              lua_pop(L, 1);
328              //get args
329              lua_pushstring(L,"prop_value");
330              lua_gettable(L, -2);
331              prop_value = lua_tostring(L,-1);
332              lua_pop(L, 1);
333          }
334         xbt_dynar_foreach(as_list_d, i, p_as)
335            {
336                    xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
337                            if (p_host->id == host_id) {
338                                    xbt_dict_set(p_host->properties, prop_id, xbt_strdup(prop_value), free);
339                            }
340                    }
341       }
342         return 1;
343
344 }
345 /*
346  * surf parse bypass platform
347  * through CPU/network Models
348  */
349
350 static int surf_parse_bypass_platform()
351 {
352   unsigned int i,j;
353   p_AS_attr p_as;
354   p_host_attr p_host;
355   p_link_attr p_link;
356   p_route_attr p_route;
357
358
359   // Add AS
360   xbt_dynar_foreach(as_list_d, i,p_as)
361   {
362     sg_platf_new_AS_open(p_as->id,p_as->mode);
363           // add associated Hosts
364           xbt_dynar_foreach(p_as->host_list_d, j, p_host){
365                   create_host(p_host->id, p_host->power_peak, p_host->power_scale,
366                                   p_host->power_trace, p_host->core, p_host->state_initial,
367                                   p_host->state_trace, p_host->properties);
368
369
370                    //FIXME: should use sg_platf instead. That would add to routing model host list, amongst other benefits
371           }
372           // add associated Links
373           xbt_dynar_foreach(p_as->link_list_d, j, p_link){
374                   create_link(p_link->id, p_link->bandwidth, p_link->bandwidth_trace,
375                                   p_link->latency, p_link->latency_trace,
376                                   p_link->state_initial, p_link->state_trace,
377                                   p_link->policy);
378           }
379           // add associated Routes
380           xbt_dynar_foreach(p_as->route_list_d, j, p_route){
381                   surf_routing_add_route((char *) p_route->src_id,
382                                              (char *) p_route->dest_id, p_route->links_id);
383           }
384
385           // Finalize AS
386           sg_platf_new_AS_close();
387   }
388
389   // add traces
390   surf_add_host_traces();
391   surf_add_link_traces();
392
393   return 0;                     // must return 0 ?!!
394
395 }
396
397 /**
398  *
399  * surf parse bypass platform
400  * through workstation_ptask_L07 Model
401  */
402
403 static int surf_wsL07_parse_bypass_platform()
404 {
405   unsigned int i,j;
406   p_AS_attr p_as, p_sub_as;
407   p_host_attr p_host;
408   p_link_attr p_link;
409   p_route_attr p_route;
410
411   xbt_dynar_foreach(as_list_d, i, p_as)
412   {
413           // Init AS
414     sg_platf_new_AS_open(p_as->id,p_as->mode);
415
416           // add Sub AS
417
418           // Add Hosts
419           xbt_dynar_foreach(p_as->sub_as_list_id, j, p_sub_as) {
420                           //...
421           }
422           xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
423             create_host_wsL07(p_host->id, p_host->power_peak, p_host->power_scale,
424                               p_host->power_trace, p_host->state_initial,
425                               p_host->state_trace);
426             //add to routing model host list
427           }
428           //add Links
429           xbt_dynar_foreach(p_as->link_list_d, j, p_link) {
430               create_link_wsL07(p_link->id, p_link->bandwidth,
431                                 p_link->bandwidth_trace, p_link->latency,
432                                 p_link->latency_trace, p_link->state_initial,
433                                 p_link->state_trace, p_link->policy);
434             }
435             // add route
436           xbt_dynar_foreach(p_as->route_list_d, j, p_route) {
437                 surf_routing_add_route((char *) p_route->src_id,
438                                        (char *) p_route->dest_id, p_route->links_id);
439               }
440           /* </AS> */
441           // Finalize AS
442           sg_platf_new_AS_close();
443   }
444   // add traces
445   surf_wsL07_add_traces();
446   return 0;
447 }
448
449 /*
450  * surf parse bypass application for MSG Module
451  */
452 static int surf_parse_bypass_application()
453 {
454   unsigned int i,j;
455   p_AS_attr p_as;
456   p_host_attr p_host;
457   xbt_dynar_foreach(as_list_d, i, p_as)
458   {
459           xbt_dynar_foreach(p_as->host_list_d, j, p_host) {
460                   if (p_host->function)
461                           MSG_set_function(p_host->id, p_host->function, p_host->args_list);
462           }
463   }
464   return 0;
465 }
466
467 /*
468  * Public Methods
469  */
470 int console_add_host(lua_State *L)
471 {
472   p_host_attr host;
473   unsigned int i;
474   p_AS_attr p_as,current_as = NULL;
475   const char *AS_id;
476   const char *id;
477   const char *power_trace;
478   const char *state_trace;
479   double power, power_scale;
480   int state_initial,core;
481   //get values from the table passed as argument
482   if (lua_istable(L, -1)) {
483   // get AS id
484   lua_pushstring(L, "AS");
485   lua_gettable(L, -2);
486   AS_id = lua_tostring(L, -1);
487   lua_pop(L,1);
488
489     // get Id Value
490     lua_pushstring(L, "id");
491     lua_gettable(L, -2);
492     id = lua_tostring(L, -1);
493     lua_pop(L, 1);
494
495     // get power value
496     lua_pushstring(L, "power");
497     lua_gettable(L, -2);
498     power = lua_tonumber(L, -1);
499     lua_pop(L, 1);
500
501     //get power_scale
502     lua_pushstring(L, "power_scale");
503     lua_gettable(L, -2);
504     power_scale = lua_tonumber(L, -1);
505     lua_pop(L, 1);
506
507     //get power_trace
508     lua_pushstring(L, "power_trace");
509     lua_gettable(L, -2);
510     power_trace = lua_tostring(L, -1);
511     lua_pop(L, 1);
512
513     lua_pushstring(L, "core");
514     lua_gettable(L, -2);
515     core = lua_tonumber(L, -1);
516     lua_pop(L, 1);
517
518     //get state initial
519     lua_pushstring(L, "state_initial");
520     lua_gettable(L, -2);
521     state_initial = lua_tonumber(L, -1);
522     lua_pop(L, 1);
523
524     //get trace state
525     lua_pushstring(L, "state_trace");
526     lua_gettable(L, -2);
527     state_trace = lua_tostring(L, -1);
528     lua_pop(L, 1);
529
530   } else {
531     XBT_ERROR
532         ("Bad Arguments to create host, Should be a table with named arguments");
533     return -1;
534   }
535   xbt_dynar_foreach(as_list_d, i, p_as){
536     if (p_as->id == AS_id){
537       current_as = p_as;
538       break;
539     }
540   }
541
542   if (!current_as)
543   {
544     XBT_ERROR("No AS_id :%s found",AS_id);
545     return -2;
546   }
547
548   host = malloc(sizeof(host_attr));
549   host->id = id;
550   host->power_peak = power;
551   host->power_scale = power_scale;
552   host->power_trace = power_trace;
553   host->core = core;
554   host->state_initial = state_initial;
555   host->state_trace = state_trace;
556   host->function = NULL;
557   host->properties = xbt_dict_new();
558   xbt_dynar_push(current_as->host_list_d, &host);
559
560   return 0;
561 }
562
563 int  console_add_link(lua_State *L) {
564   const char *AS_id;
565   unsigned int i;
566   p_AS_attr p_as,current_as = NULL;
567   const char* id;
568   double bandwidth, latency;
569   const char *bandwidth_trace;
570   const char *latency_trace;
571   const char *state_trace;
572   int state_initial, policy;
573
574   //get values from the table passed as argument
575   if (lua_istable(L, -1)) {
576
577   //get AS id
578   lua_pushstring(L, "AS");
579   lua_gettable(L, -2);
580   AS_id = lua_tostring(L, -1);
581   lua_pop(L, 1);
582
583     // get Id Value
584     lua_pushstring(L, "id");
585     lua_gettable(L, -2);
586     id = lua_tostring(L, -1);
587     lua_pop(L, 1);
588
589     // get bandwidth value
590     lua_pushstring(L, "bandwidth");
591     lua_gettable(L, -2);
592     bandwidth = lua_tonumber(L, -1);
593     lua_pop(L, 1);
594
595     //get latency value
596     lua_pushstring(L, "latency");
597     lua_gettable(L, -2);
598     latency = lua_tonumber(L, -1);
599     lua_pop(L, 1);
600
601     /*Optional Arguments  */
602
603     //get bandwidth_trace value
604     lua_pushstring(L, "bandwidth_trace");
605     lua_gettable(L, -2);
606     bandwidth_trace = lua_tostring(L, -1);
607     lua_pop(L, 1);
608
609     //get latency_trace value
610     lua_pushstring(L, "latency_trace");
611     lua_gettable(L, -2);
612     latency_trace = lua_tostring(L, -1);
613     lua_pop(L, 1);
614
615     //get state_trace value
616     lua_pushstring(L, "state_trace");
617     lua_gettable(L, -2);
618     state_trace = lua_tostring(L, -1);
619     lua_pop(L, 1);
620
621     //get state_initial value
622     lua_pushstring(L, "state_initial");
623     lua_gettable(L, -2);
624     state_initial = lua_tonumber(L, -1);
625     lua_pop(L, 1);
626
627     //get policy value
628     lua_pushstring(L, "policy");
629     lua_gettable(L, -2);
630     policy = lua_tonumber(L, -1);
631     lua_pop(L, 1);
632
633   } else {
634     XBT_ERROR
635         ("Bad Arguments to create link, Should be a table with named arguments");
636     return -1;
637   }
638   xbt_dynar_foreach(as_list_d, i, p_as){
639     if (p_as->id == AS_id){
640       current_as = p_as;
641       break;
642     }
643   }
644
645   if (!current_as)
646   {
647     XBT_ERROR("No AS_id :%s found",AS_id);
648     return -2;
649   }
650   p_link_attr link = malloc(sizeof(link_attr));
651   link->id = id;
652   link->bandwidth = bandwidth;
653   link->latency = latency;
654   link->bandwidth_trace = bandwidth_trace;
655   link->latency_trace = latency_trace;
656   link->state_trace = state_trace;
657   link->state_initial = state_initial;
658   link->policy = policy;
659   xbt_dynar_push(current_as->link_list_d, &link);
660
661   return 0;
662 }
663 /**
664  * add Router to AS components
665  */
666 int console_add_router(lua_State* L) {
667   p_router_attr router;
668   const char* AS_id;
669   unsigned int i;
670   p_AS_attr p_as,current_as = NULL;
671   const char* id;
672   if (lua_istable(L, -1)) {
673     // get AS id
674     lua_pushstring(L, "AS");
675     lua_gettable(L, -2);
676     AS_id = lua_tostring(L, -1);
677     lua_pop(L,1);
678
679     lua_pushstring(L, "id");
680     lua_gettable(L, -2);
681     id = lua_tostring(L, -1);
682     lua_pop(L,1);
683   }
684   xbt_dynar_foreach(as_list_d, i, p_as){
685       if (p_as->id == AS_id){
686         current_as = p_as;
687         break;
688       }
689     }
690
691     if (!current_as)
692     {
693       XBT_ERROR("No AS_id '%s' found",AS_id);
694       return -2;
695     }
696   router = malloc(sizeof(router_attr));
697   router->id = id;
698   xbt_dynar_push(current_as->router_list_d, &router);
699   return 0;
700
701 }
702
703
704 int console_add_route(lua_State *L)
705 {
706   const char* AS_id;
707   unsigned int i;
708   p_AS_attr p_as,current_as = NULL;
709   const char *links;
710   const char* link_id;
711   p_route_attr route = malloc(sizeof(route_attr));
712
713
714   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)
715
716    //get AS_id
717    lua_pushstring(L, "AS");
718    lua_gettable(L, -2);
719    AS_id = lua_tostring(L, -1);
720    lua_pop(L, 1);
721
722    xbt_dynar_foreach(as_list_d, i, p_as){
723     if (p_as->id == AS_id){
724       current_as = p_as;
725       break;
726     }
727    }
728
729    if (!current_as)
730    {
731     XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
732     return -2;
733    }
734    // get Source Value
735      lua_pushstring(L, "src");
736      lua_gettable(L, -2);
737      route->src_id = lua_tostring(L, -1);
738      lua_pop(L, 1);
739
740      // get Destination Value
741      lua_pushstring(L, "dest");
742      lua_gettable(L, -2);
743      route->dest_id = lua_tostring(L, -1);
744      lua_pop(L, 1);
745
746      // get Links Table (char* to be splited later)
747      lua_pushstring(L, "links");
748      lua_gettable(L, -2);
749      links = lua_tostring(L, -1);
750      lua_pop(L,1);
751
752      route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
753
754      char *tmp_links = xbt_strdup(links);
755      link_id = strtok(tmp_links,",");   //tmp_link = strtok((char*)links,",");
756      while(link_id != NULL)
757        {
758           xbt_dynar_push(route->links_id, &link_id);
759           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.
760         }
761      xbt_dynar_push(current_as->route_list_d, &route);
762      return 0;
763       }
764   else { // Route.new is declared as a function
765    AS_id = luaL_checkstring(L, 1);
766    xbt_dynar_foreach(as_list_d, i, p_as){
767       if (p_as->id == AS_id){
768         current_as = p_as;
769         break;
770       }
771      }
772
773    if (!current_as)
774    {
775     XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
776     return -2;
777    }
778      route->src_id = luaL_checkstring(L, 2);
779      route->dest_id = luaL_checkstring(L, 3);
780      route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
781      lua_pushnil(L);
782      while (lua_next(L, 4) != 0)
783     {
784        link_id = lua_tostring(L, -1);
785        xbt_dynar_push(route->links_id, &link_id);
786          XBT_DEBUG("index = %f , Link_id = %s \n", lua_tonumber(L, -2),
787        lua_tostring(L, -1));
788        lua_pop(L, 1);
789       }
790     lua_pop(L, 1);
791     //add route to platform's route list
792     xbt_dynar_push(current_as->route_list_d, &route);
793     return 0;
794     }
795
796   return -1;
797 }
798
799 int console_add_AS(lua_State *L)
800 {
801         return AS_new(L);
802 }
803
804 int console_set_function(lua_State *L)
805 {
806         return Host_set_function(L);
807 }
808
809 int console_host_set_property(lua_State *L)
810 {
811         return Host_set_property(L);
812 }
813
814 int console_parse_platform()
815 {
816         return surf_parse_bypass_platform();
817 }
818
819 int  console_parse_application()
820 {
821         return surf_parse_bypass_application();
822 }
823
824 int console_parse_platform_wsL07()
825 {
826         return surf_wsL07_parse_bypass_platform();
827 }