XBT_PUBLIC(xbt_dynar_t) xbt_str_split(const char *s, const char *sep);
XBT_PUBLIC(xbt_dynar_t) xbt_str_split_quoted(const char *s);
+XBT_PUBLIC(xbt_dynar_t) xbt_str_split_str(const char *s, const char *sep);
+
XBT_PUBLIC(char *) xbt_str_join(xbt_dynar_t dynar, const char *sep);
/* */
void parse_properties(void);
void free_string(void*);
+/* Prototypes for functions handling routing and were factorized succesfully from the models */
+void init_route_table(void);
+void make_route_table(void);
+void parse_route_elem(void);
+
+/* surf parse file related */
+void parse_platform_file(const char* file);
+
SG_END_DECL()
#endif /* _SURF_SURF_H */
surf_workstation_model_description[workstation_id].
model_init(platform_file);
+ parse_platform_file(platform_file);
+
_sd_init_status = 2;
/* now let's create the SD wrappers for workstations and links */
/* SGU: BEGIN FILE xbt/xbt_str.c */
void test_split_quoted(void);
+ void test_split_str(void);
/* SGU: END FILE */
/* SGU: BEGIN FILE xbt/config.c */
/* SGU: BEGIN FILE xbt/xbt_str.c */
suite = xbt_test_suite_by_name("xbt_str","String Handling");
xbt_test_suite_push(suite, "xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted");
+ xbt_test_suite_push(suite, "xbt_str_split_str", test_split_str, "test the function xbt_str_split_str");
/* SGU: END FILE */
/* SGU: BEGIN FILE xbt/config.c */
{
xbt_assert0(simix_global,
"SIMIX_global_init has to be called before SIMIX_launch_application.");
+ surf_parse_reset_parser();
surfxml_add_callback(STag_surfxml_process_cb_list, parse_process_init);
surfxml_add_callback(ETag_surfxml_argument_cb_list, parse_argument);
surfxml_add_callback(STag_surfxml_prop_cb_list, parse_properties);
#include "private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
+
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix,
"Logging specific to SIMIX (environment)");
surf_cpu_model_description[cpu_id].model_init(file);
surf_network_model_description[network_id].model_init(file);
+
}
surf_workstation_model_description[workstation_id].
model_init(file);
+ /* Parse the platform file */
+ parse_platform_file(file);
+
_simix_init_status = 2; /* inited; don't change settings now */
xbt_dict_foreach(workstation_set, cursor, name, workstation) {
}
-static void parse_file(const char *file)
+static void define_callbacks(const char *file)
{
surf_parse_reset_parser();
surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_init);
- surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
-
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
+ surfxml_add_callback(STag_surfxml_prop_cb_list, parse_properties);
}
static void *name_service(const char *name)
if (surf_cpu_model)
return;
surf_cpu_model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_cpu_model);
}
xbt_dict_t network_card_set = NULL;
int card_number = 0;
+int host_number = 0;
link_CM02_t **routing_table = NULL;
int *routing_table_size = NULL;
static link_CM02_t loopback = NULL;
static void create_routing_table(void)
{
routing_table =
- xbt_new0(link_CM02_t *, card_number * card_number);
- routing_table_size = xbt_new0(int, card_number * card_number);
+ xbt_new0(link_CM02_t *, /*card_number * card_number */ host_number * host_number);
+ routing_table_size = xbt_new0(int, /*card_number * card_number*/ host_number * host_number);
}
static void link_free(void *nw_link)
}
-static int nb_link;
-static int link_list_capacity;
-static link_CM02_t *link_list = NULL;
static int src_id = -1;
static int dst_id = -1;
static void parse_route_set_endpoints(void)
{
-
src_id = network_card_new(A_surfxml_route_src);
dst_id = network_card_new(A_surfxml_route_dst);
- nb_link = 0;
- link_list_capacity = 20;
- link_list = xbt_new(link_CM02_t, link_list_capacity);
-}
-static void parse_route_elem(void)
-{
-
- if (nb_link == link_list_capacity) {
- link_list_capacity *= 2;
- link_list =
- xbt_realloc(link_list,
- (link_list_capacity) * sizeof(link_CM02_t));
- }
- link_list[nb_link++] =
- xbt_dict_get_or_null(link_set, A_surfxml_link_c_ctn_id);
+ route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
}
static void parse_route_set_route(void)
{
- route_new(src_id, dst_id, link_list, nb_link);
+ char *name;
+ if (src_id != -1 && dst_id != -1) {
+ name = bprintf("%d##%d",src_id, dst_id);
+ xbt_dict_set(route_table, name, route_link_list, NULL);
+ free(name);
+ }
}
-static void parse_file(const char *file)
+static void add_loopback()
{
int i;
- /* Figuring out the network links */
- surf_parse_reset_parser();
- surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
- surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
-
- /* Figuring out the network cards used */
- surf_parse_reset_parser();
- surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
-
- create_routing_table();
-
- /* Building the routes */
- surf_parse_reset_parser();
- surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
- surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
-
/* Adding loopback if needed */
-
- for (i = 0; i < card_number; i++)
+ for (i = 0; i < host_number; i++)
if (!ROUTE_SIZE(i, i)) {
if (!loopback)
loopback = link_new(xbt_strdup("__MSG_loopback__"),
}
}
+static void add_route()
+{
+ xbt_ex_t e;
+ int nb_link = 0;
+ int cpt = 0;
+ int link_list_capacity = 0;
+ link_CM02_t *link_list = NULL;
+
+ if (routing_table == NULL) create_routing_table();
+
+ link_list_capacity = xbt_dynar_length(links);
+ link_list = xbt_new(link_CM02_t, link_list_capacity);
+
+ src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
+ dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
+
+ char* link = NULL;
+ xbt_dynar_foreach (links, cpt, link) {
+ TRY {
+ link_list[nb_link++] = xbt_dict_get(link_set, link);
+ }
+ CATCH(e) {
+ RETHROW1("Link %s not found (dict raised this exception: %s)", link);
+ }
+ }
+ route_new(src_id, dst_id, link_list, nb_link);
+
+}
+
+static void count_hosts(void)
+{
+ host_number++;
+}
+
+static void define_callbacks(const char *file)
+{
+ /* Figuring out the network links */
+ surfxml_add_callback(STag_surfxml_host_cb_list, &count_hosts);
+ surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
+ surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
+ surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
+ surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
+ surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
+ surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
+}
+
static void *name_service(const char *name)
{
network_card_CM02_t card = xbt_dict_get_or_null(network_card_set, name);
if (surf_network_model)
return;
surf_network_model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_network_model);
network_solve = lmm_solve;
if (surf_network_model)
return;
surf_network_model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_network_model);
lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
if (surf_network_model)
return;
surf_network_model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_network_model);
lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
if (surf_network_model)
return;
surf_network_model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_network_model);
network_solve = sdp_solve;
{
src_id = network_card_new(A_surfxml_route_src);
dst_id = network_card_new(A_surfxml_route_dst);
- nb_link = 0;
+
+/* nb_link = 0;
link_name = NULL;
+*/
+ route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
}
/* KF*/
}
}
+//The following is common to all and has been relocated to surfxml_parse
/* Parses a route element from the XML: UNMODIFIED BY HC */
-static void parse_route_elem(void)
+/*static void parse_route_elem(void)
{
nb_link++;
link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name);
}
+*/
/* Create the route (more than one hops): MODIFIED BY KF */
static void parse_route_set_route(void)
{
- if (nb_link > 1)
+/* if (nb_link > 1)
route_new(src_id, dst_id, link_name, nb_link);
+*/
+ name = bprintf("%d##%d",src_id, dst_id);
+ xbt_dict_set(route_table, name, route_link_list, NULL);
+ free(name);
}
+//This is not used anymore. one hop routes are created in add_route
/* Create the one-hope route: BY KF */
static void parse_route_set_onehop_route(void)
{
route_onehop_new(src_id, dst_id, link_name, nb_link);
}
-/* Main XML parsing */
-static void parse_file(const char *file)
+static void add_route()
{
- surf_parse_reset_parser();
+ xbt_ex_t e;
+ int cpt = 0;
+ int i = 0;
+
+ nb_link = xbt_dynar_length(links);
+ link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
+ src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
+ dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
+
+ i = 0;
+ char* link = NULL;
+ xbt_dynar_foreach (links, cpt, link) {
+ TRY {
+ link_name[i++] = xbt_dict_get(link_set, link);
+ }
+ CATCH(e) {
+ RETHROW1("Link %s not found (dict raised this exception: %s)", link);
+ }
+ }
+ if (nb_link > 1)
+ route_new(src_id, dst_id, link_name, nb_link);
+ if (nb_link == 1)
+ route_onehop_new(src_id, dst_id, link_name, nb_link);
+}
+
+/* Main XML parsing */
+static void define_callbacks(const char *file)
+{
surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
surfxml_add_callback(STag_surfxml_router_cb_list, &parse_route_set_routers);
surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
surfxml_add_callback(ETag_surfxml_route_element_cb_list, &parse_route_elem);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_onehop_route);
+/* surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_onehop_route);*/
surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
-
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
}
static void *name_service(const char *name)
if (surf_network_model)
return;
surf_network_model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_network_model);
update_model_description(surf_network_model_description,
path_name = NULL;
}
surf_parse_free_callbacks();
+ xbt_dict_free(&route_table);
NOW=0; /* Just in case the user plans to restart the simulation afterward */
xbt_exit();
}
xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
xbt_dict_t current_property_set = NULL;
-
+
+xbt_dict_t route_table = NULL;
+xbt_dynar_t route_link_list = NULL;
+xbt_dynar_t links = NULL;
+xbt_dynar_t keys = NULL;
+
static xbt_dynar_t surf_input_buffer_stack = NULL;
static xbt_dynar_t surf_file_to_parse_stack = NULL;
YY_BUFFER_STATE surf_input_buffer;
FILE *surf_file_to_parse;
+void make_route_table(void)
+{
+ xbt_dict_cursor_t cursor = NULL;
+ char *key,*data;
+ const char *sep = "##";
+
+ xbt_dict_foreach(route_table, cursor, key, data) {
+ links = (xbt_dynar_t)data;
+ keys = xbt_str_split_str(key, sep);
+ surfxml_call_cb_functions(ETag_surfxml_platform_cb_list);
+ }
+
+ xbt_dict_free(&route_table);
+ xbt_dynar_free(&links);
+
+}
+
void surf_parse_free_callbacks(void)
{
xbt_dynar_free(&STag_surfxml_platform_cb_list);
void ETag_surfxml_platform(void)
{
- surfxml_call_cb_functions(ETag_surfxml_platform_cb_list);
+ if (route_table != NULL) make_route_table();
}
void STag_surfxml_host(void)
(*fun)();
}
}
+
+void init_route_table(void)
+{
+ xbt_dict_free(&route_table);
+ xbt_dynar_free(&route_link_list);
+ route_table = xbt_dict_new();
+}
+
+void parse_route_elem(void)
+{
+ char *val;
+ val = xbt_strdup(A_surfxml_link_c_ctn_id);
+ xbt_dynar_push(route_link_list, &val);
+}
+
+void parse_platform_file(const char* file)
+{
+ surf_parse_open(file);
+ xbt_assert1((!surf_parse()), "Parse error in %s", file);
+ surf_parse_close();
+}
surf_parse_get_double(&max_outgoing_rate,
A_surfxml_host_max_outgoing_rate);
current_property_set = xbt_dict_new();
+
cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace,
state_initial, state_trace, interference_send, interference_recv,
interference_send_recv, max_outgoing_rate,current_property_set);
route->impact_on_dst = impact_on_dst;
route->impact_on_src_with_other_recv = impact_on_src_with_other_recv;
route->impact_on_dst_with_other_send = impact_on_dst_with_other_send;
-
}
-static int nb_link;
-static int link_list_capacity;
-static link_KCCFLN05_t *link_list = NULL;
static int src_id = -1;
static int dst_id = -1;
static double impact_on_src;
static double impact_on_dst;
static double impact_on_src_with_other_recv;
static double impact_on_dst_with_other_send;
-static int is_first = 1;
static void parse_route_set_endpoints(void)
{
cpu_KCCFLN05_t cpu_tmp = NULL;
- if (is_first) create_routing_table();
- is_first = 0;
-
cpu_tmp = (cpu_KCCFLN05_t) name_service(A_surfxml_route_src);
if (cpu_tmp != NULL) {
src_id = cpu_tmp->id;
surf_parse_get_double(&impact_on_dst_with_other_send,
A_surfxml_route_impact_on_dst_with_other_send);
- nb_link = 0;
- link_list_capacity = 1;
- link_list = xbt_new(link_KCCFLN05_t, link_list_capacity);
-
+ route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
}
-static void parse_route_elem(void)
+static void parse_route_set_route(void)
{
- xbt_ex_t e;
- if (nb_link == link_list_capacity) {
- link_list_capacity *= 2;
- link_list =
- xbt_realloc(link_list,
- (link_list_capacity) *
- sizeof(link_KCCFLN05_t));
- }
- TRY {
- link_list[nb_link++] =
- xbt_dict_get(link_set, A_surfxml_link_c_ctn_id);
- }
- CATCH(e) {
- RETHROW1("Link %s not found (dict raised this exception: %s)",
- A_surfxml_link_c_ctn_id);
+ char* name;
+ if (src_id != -1 && dst_id != -1) {
+ name = bprintf("%d##%d##%lf##%lf##%lf##%lf",src_id, dst_id,impact_on_src,
+ impact_on_dst, impact_on_src_with_other_recv,
+ impact_on_dst_with_other_send);
+ xbt_dict_set(route_table, name, route_link_list, NULL);
+ free(name);
}
}
-static void parse_route_set_route(void)
+static void add_loopback()
{
- if (src_id != -1 && dst_id != -1)
- route_new(src_id, dst_id, link_list, nb_link, impact_on_src,
+ int i;
+ /* Adding loopback if needed */
+ for (i = 0; i < nb_workstation; i++) {
+ if (!ROUTE(i, i).size) {
+ if (!loopback)
+ loopback = link_new(xbt_strdup("__MSG_loopback__"),
+ 498000000, NULL, 0.000015, NULL,
+ SURF_LINK_ON, NULL,
+ SURF_LINK_FATPIPE, NULL);
+ ROUTE(i, i).size = 1;
+ ROUTE(i, i).links = xbt_new0(link_KCCFLN05_t, 1);
+ ROUTE(i, i).links[0] = loopback;
+ }
+ }
+}
+
+static void add_route()
+{
+ xbt_ex_t e;
+ int nb_link = 0;
+ int cpt = 0;
+ int link_list_capacity = 0;
+ link_KCCFLN05_t *link_list = NULL;
+
+ if (routing_table == NULL) create_routing_table();
+
+ link_list_capacity = xbt_dynar_length(links);
+ link_list = xbt_new(link_KCCFLN05_t, link_list_capacity);
+
+ src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
+ dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
+ impact_on_src = atof(xbt_dynar_get_as(keys, 2, char*));
+ impact_on_dst = atof(xbt_dynar_get_as(keys, 3, char*));
+ impact_on_src_with_other_recv = atof(xbt_dynar_get_as(keys, 4, char*));
+ impact_on_dst_with_other_send = atof(xbt_dynar_get_as(keys, 5, char*));
+
+ char* link = NULL;
+ xbt_dynar_foreach (links, cpt, link) {
+ TRY {
+ link_list[nb_link++] = xbt_dict_get(link_set, link);
+ }
+ CATCH(e) {
+ RETHROW1("Link %s not found (dict raised this exception: %s)", link);
+ }
+ }
+ route_new(src_id, dst_id, link_list, nb_link,impact_on_src,
impact_on_dst, impact_on_src_with_other_recv,
impact_on_dst_with_other_send);
}
-
-static void parse_file(const char *file)
+static void define_callbacks(const char *file)
{
- int i;
-
CDEBUG0(surf_parse, "Use the KCCFKN05 model");
/* Adding callback functions */
surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-
- /* Parse the file */
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
-
- /* Adding loopback if needed */
- for (i = 0; i < nb_workstation; i++)
- if (!ROUTE(i, i).size) {
- if (!loopback)
- loopback = link_new(xbt_strdup("__MSG_loopback__"),
- 498000000, NULL, 0.000015, NULL,
- SURF_LINK_ON, NULL,
- SURF_LINK_FATPIPE, NULL);
- ROUTE(i, i).size = 1;
- ROUTE(i, i).links = xbt_new0(link_KCCFLN05_t, 1);
- ROUTE(i, i).links[0] = loopback;
- }
-
+ surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
}
/**************************************/
xbt_assert0(!surf_network_model,
"network model type already defined");
model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
xbt_dynar_push(model_list, &surf_workstation_model);
}
}
static void route_new(int src_id, int dst_id,
- link_L07_t * link_list, int nb_link)
+ link_L07_t * link_list , int nb_link)
{
route_L07_t route = &(ROUTE(src_id, dst_id));
route->size = nb_link;
- route->links = link_list =
- xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
+ route->links = link_list = xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
}
-static int nb_link;
-static int link_list_capacity;
-static link_L07_t *link_list = NULL;
+
static int src_id = -1;
static int dst_id = -1;
-static int is_first =1;
static void parse_route_set_endpoints(void)
{
cpu_L07_t cpu_tmp = NULL;
- if (is_first) create_routing_table();
- is_first = 0;
-
cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
if (cpu_tmp != NULL)
if (cpu_tmp != NULL)
dst_id = cpu_tmp->id;
- nb_link = 0;
- link_list_capacity = 1;
- link_list = xbt_new(link_L07_t, link_list_capacity);
-}
-
-static void parse_route_elem(void)
-{
- xbt_ex_t e;
- if (nb_link == link_list_capacity) {
- link_list_capacity *= 2;
- link_list =
- xbt_realloc(link_list,
- (link_list_capacity) * sizeof(link_L07_t));
- }
- TRY {
- link_list[nb_link++] =
- xbt_dict_get(link_set, A_surfxml_link_c_ctn_id);
- }
- CATCH(e) {
- RETHROW1("Link %s not found (dict raised this exception: %s)",
- A_surfxml_link_c_ctn_id);
- }
+ route_link_list = xbt_dynar_new(sizeof(char*), &free_string);
}
static void parse_route_set_route(void)
{
- if (src_id != -1 && dst_id != -1)
- route_new(src_id, dst_id, link_list, nb_link);
+ char* name;
+ if (src_id != -1 && dst_id != -1) {
+ name = bprintf("%d##%d",src_id, dst_id);
+ xbt_dict_set(route_table, name, route_link_list, NULL);
+ free(name);
+ }
}
-static void parse_file(const char *file)
+static void add_loopback(void)
{
int i;
-
- /* Adding callback functions */
- surf_parse_reset_parser();
- surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
- surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
- surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
- surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
- surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-
- /* Parse the file */
- surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
- surf_parse_close();
-
/* Adding loopback if needed */
for (i = 0; i < nb_workstation; i++)
if (!ROUTE(i, i).size) {
}
}
+static void add_route()
+{
+ xbt_ex_t e;
+ int nb_link = 0;
+ int cpt = 0;
+ // char* val;
+ int link_list_capacity = 0;
+ link_L07_t *link_list = NULL;
+
+ if (routing_table == NULL) create_routing_table();
+
+ src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
+ dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
+
+ link_list_capacity = xbt_dynar_length(links);
+ link_list = xbt_new(link_L07_t, link_list_capacity);
+
+ char* link = NULL;
+ xbt_dynar_foreach (links, cpt, link) {
+ TRY {
+ link_list[nb_link++] = xbt_dict_get(link_set, link);
+ }
+ CATCH(e) {
+ RETHROW1("Link %s not found (dict raised this exception: %s)", link);
+ }
+ }
+ route_new(src_id, dst_id, link_list, nb_link);
+}
+
+static void define_callbacks(const char *file)
+{
+ /* Adding callback functions */
+ surf_parse_reset_parser();
+ surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
+ surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
+ surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
+ surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
+ surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
+ surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
+ surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
+}
+
/**************************************/
/********* Module creation ***********/
/**************************************/
xbt_assert0(!surf_network_model,
"network model type already defined");
model_init_internal();
- parse_file(filename);
+ define_callbacks(filename);
update_model_description(surf_workstation_model_description,
surf_workstation_model_description_size,
return res;
}
+/**
+ * \brief This functions splits a string after using another string as separator
+ * For example A##B##C splitted after ## will return the dynar {A,B,C}
+ * \return An array of dynars containing the string tokens
+*/
+xbt_dynar_t xbt_str_split_str(const char *s, const char *sep) {
+ xbt_dynar_t res = xbt_dynar_new(sizeof(char*), free_string);
+ int done;
+ const char *p, *q;
+
+ p = q = s;
+ done = 0;
+
+ if (s[0] == '\0')
+ return res;
+ if (sep[0] == '\0') {
+ xbt_dynar_push(res, &s);
+ return res;
+ }
+
+ while (!done) {
+ char *to_push;
+ int v = 0;
+ //get the start of the first occurence of the substring
+ q = strstr(p, sep);
+ //if substring was not found add the entire string
+ if (NULL == q) {
+ v = strlen(p);
+ to_push = malloc(v + 1);
+ memcpy(to_push, p, v);
+ to_push[v] = '\0';
+ xbt_dynar_push(res, &to_push);
+ done = 1;
+ }
+ else {
+ //get the appearance
+ to_push = malloc(q - p + 1);
+ memcpy(to_push, p, q - p);
+ //add string terminator
+ to_push[q - p] = '\0';
+ xbt_dynar_push(res, &to_push);
+ p = q +strlen(sep);
+ }
+ }
+ return res;
+}
+
/** @brief Splits a string into a dynar of strings, taking quotes into account
*
* It basically does the same argument separation than the shell, where white
mytest("Backslashed quotes + quotes", "'toto \\'tutu' tata", "toto 'tutuXXXtata");
}
+
+#define mytest_str(name, input, separator, expected) \
+ xbt_test_add0(name); \
+ d=xbt_str_split_str(input, separator); \
+ s=xbt_str_join(d,"XXX"); \
+ xbt_test_assert3(!strcmp(s,expected),\
+ "Input (%s) leads to (%s) instead of (%s)", \
+ input,s,expected);\
+ free(s); \
+ xbt_dynar_free(&d);
+
+XBT_TEST_UNIT("xbt_str_split_str",test_split_str, "test the function xbt_str_split_str") {
+ xbt_dynar_t d;
+ char *s;
+
+ mytest_str("Empty string and separator", "", "", "");
+ mytest_str("Empty string", "", "##", "");
+ mytest_str("Empty separator", "toto", "", "toto");
+ mytest_str("String with no separator in it", "toto", "##", "toto");
+ mytest_str("Basic test", "toto##tutu", "##", "totoXXXtutu");
+}
#endif /* SIMGRID_TEST */
/** @brief Join a set of strings as a single string */
/* GENERATED FILE, DO NOT EDIT */
/*******************************/
-# 339 "xbt/xbt_str.c"
+# 386 "xbt/xbt_str.c"
#define mytest(name, input, expected) \
xbt_test_add0(name); \
d=xbt_str_split_quoted(input); \
mytest("Backslashed quotes + quotes", "'toto \\'tutu' tata", "toto 'tutuXXXtata");
}
+
+#define mytest_str(name, input, separator, expected) \
+ xbt_test_add0(name); \
+ d=xbt_str_split_str(input, separator); \
+ s=xbt_str_join(d,"XXX"); \
+ xbt_test_assert3(!strcmp(s,expected),\
+ "Input (%s) leads to (%s) instead of (%s)", \
+ input,s,expected);\
+ free(s); \
+ xbt_dynar_free(&d);
+
+XBT_TEST_UNIT("xbt_str_split_str",test_split_str, "test the function xbt_str_split_str") {
+ xbt_dynar_t d;
+ char *s;
+
+ mytest_str("Empty string and separator", "", "", "");
+ mytest_str("Empty string", "", "##", "");
+ mytest_str("Empty separator", "toto", "", "toto");
+ mytest_str("String with no separator in it", "toto", "##", "toto");
+ mytest_str("Basic test", "toto##tutu", "##", "totoXXXtutu");
+}
/*******************************/
/* GENERATED FILE, DO NOT EDIT */
/*******************************/