~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to src/surf/surf_routing.c

  • Committer: Package Import Robot
  • Author(s): Martin Quinson
  • Date: 2013-01-31 00:24:51 UTC
  • mfrom: (10.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130131002451-krejhf7w7h24lpsc
Tags: 3.9~rc1-1
* New upstream release: the "Grasgory" release. Major changes:
  - Gras was completely removed from this version.
  - Documentation reorganization to ease browsing it.
  - New default value for the TCP_gamma parameter: 4MiB

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
/* This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of the license (GNU LGPL) which comes with this package. */
6
6
 
7
 
#include <pcre.h>               /* regular expression library */
8
 
 
9
7
#include "simgrid/platf_interface.h"    // platform creation API internal interface
10
8
 
11
9
#include "surf_routing_private.h"
27
25
int COORD_HOST_LEVEL=0;         //Coordinates level
28
26
int NS3_HOST_LEVEL;             //host node for ns3
29
27
 
 
28
xbt_dict_t watched_hosts_lib;
 
29
 
30
30
/**
31
31
 * @ingroup SURF_build_api
32
32
 * @brief A library containing all known links
40
40
int ROUTING_ASR_LEVEL;          //Routing level
41
41
int COORD_ASR_LEVEL;            //Coordinates level
42
42
int NS3_ASR_LEVEL;              //host node for ns3
 
43
int ROUTING_PROP_ASR_LEVEL;     //Where the properties are stored
43
44
 
44
45
static xbt_dict_t random_value = NULL;
45
46
 
58
59
AS_t current_routing = NULL;
59
60
 
60
61
/* global parse functions */
61
 
xbt_dynar_t parsed_link_list = NULL;   /* temporary store of current list link of a route */
62
62
extern xbt_dynar_t mount_list;
63
63
 
64
 
static const char *src = NULL;  /* temporary store the source name of a route */
65
 
static const char *dst = NULL;  /* temporary store the destination name of a route */
66
 
static char *gw_src = NULL;     /* temporary store the gateway source name of a route */
67
 
static char *gw_dst = NULL;     /* temporary store the gateway destination name of a route */
68
 
 
69
64
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
70
65
 
71
66
static void routing_parse_peer(sg_platf_peer_cbarg_t peer);     /* peer bypass */
110
105
};
111
106
 
112
107
/**
 
108
 * \brief Add a "host_link" to the network element list
 
109
 */
 
110
static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
 
111
{
 
112
  sg_routing_edge_t info = NULL;
 
113
  info = xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL);
 
114
  xbt_assert(info, "Host '%s' not found!",host->id);
 
115
  xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER] ||
 
116
      current_routing->model_desc == &routing_models[SURF_MODEL_VIVALDI],
 
117
      "You have to be in model Cluster to use tag host_link!");
 
118
 
 
119
  s_surf_parsing_link_up_down_t link_up_down;
 
120
  link_up_down.link_up = xbt_lib_get_or_null(link_lib, host->link_up, SURF_LINK_LEVEL);
 
121
  link_up_down.link_down = xbt_lib_get_or_null(link_lib, host->link_down, SURF_LINK_LEVEL);
 
122
 
 
123
  xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up);
 
124
  xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down);
 
125
 
 
126
  if(!current_routing->link_up_down_list)
 
127
    current_routing->link_up_down_list = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
 
128
 
 
129
  // If dynar is is greater than edge id and if the host_link is already defined
 
130
  if(xbt_dynar_length(current_routing->link_up_down_list) > info->id &&
 
131
      xbt_dynar_get_as(current_routing->link_up_down_list,info->id,void*))
 
132
    xbt_die("Host_link for '%s' is already defined!",host->id);
 
133
 
 
134
  XBT_DEBUG("Push Host_link for host '%s' to position %d",info->name,info->id);
 
135
  xbt_dynar_set_as(current_routing->link_up_down_list,info->id,s_surf_parsing_link_up_down_t,link_up_down);
 
136
}
 
137
 
 
138
/**
113
139
 * \brief Add a "host" to the network element list
114
140
 */
115
141
static void parse_S_host(sg_platf_host_cbarg_t host)
120
146
  xbt_assert(!xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL),
121
147
             "Reading a host, processing unit \"%s\" already exists", host->id);
122
148
 
123
 
  info = xbt_new0(s_network_element_t, 1);
 
149
  info = xbt_new0(s_routing_edge_t, 1);
124
150
  info->rc_component = current_routing;
125
151
  info->rc_type = SURF_NETWORK_ELEMENT_HOST;
126
152
  info->name = xbt_strdup(host->id);
165
191
             "Reading a router, processing unit \"%s\" already exists",
166
192
             router->id);
167
193
 
168
 
  info = xbt_new0(s_network_element_t, 1);
 
194
  info = xbt_new0(s_routing_edge_t, 1);
169
195
  info->rc_component = current_routing;
170
196
  info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
171
197
  info->name = xbt_strdup(router->id);
173
199
  xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
174
200
  XBT_DEBUG("Having set name '%s' id '%d'",router->id,info->id);
175
201
 
176
 
  if (strcmp(router->coord, "")) {
 
202
  if (router->coord && strcmp(router->coord, "")) {
177
203
    unsigned int cursor;
178
204
    char*str;
179
205
 
193
219
  }
194
220
}
195
221
 
196
 
 
197
 
/**
198
 
 * \brief Set the end points for a route
199
 
 */
200
 
static void routing_parse_S_route(void)
201
 
{
202
 
  src = A_surfxml_route_src;
203
 
  dst = A_surfxml_route_dst;
204
 
  xbt_assert(strlen(src) > 0 || strlen(dst) > 0,
205
 
             "Missing end-points while defining route \"%s\"->\"%s\"",
206
 
             src, dst);
207
 
  parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
208
 
}
209
 
 
210
 
/**
211
 
 * \brief Set the end points and gateways for a ASroute
212
 
 */
213
 
static void routing_parse_S_ASroute(void)
214
 
{
215
 
  src = A_surfxml_ASroute_src;
216
 
  dst = A_surfxml_ASroute_dst;
217
 
  gw_src = A_surfxml_ASroute_gw_src;
218
 
  gw_dst = A_surfxml_ASroute_gw_dst;
219
 
  xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 || strlen(gw_dst) > 0,
220
 
             "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
221
 
             src, dst,gw_src,gw_dst);
222
 
  parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
223
 
}
224
 
 
225
 
/**
226
 
 * \brief Set the end points for a bypassRoute
227
 
 */
228
 
static void routing_parse_S_bypassRoute(void)
229
 
{
230
 
  src = A_surfxml_bypassRoute_src;
231
 
  dst = A_surfxml_bypassRoute_dst;
232
 
  gw_src = NULL;
233
 
  gw_dst = NULL;
234
 
  xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 || strlen(gw_dst) > 0,
235
 
             "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
236
 
             src, dst,gw_src,gw_dst);
237
 
  parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
238
 
}
239
 
 
240
 
/**
241
 
 * \brief Set the end points for a bypassASroute
242
 
 */
243
 
static void routing_parse_S_bypassASroute(void)
244
 
{
245
 
  src = A_surfxml_bypassASroute_src;
246
 
  dst = A_surfxml_bypassASroute_dst;
247
 
  gw_src = A_surfxml_bypassASroute_gw_src;
248
 
  gw_dst = A_surfxml_bypassASroute_gw_dst;
249
 
  xbt_assert(strlen(src) > 0 || strlen(dst) > 0 || strlen(gw_src) > 0 || strlen(gw_dst) > 0,
250
 
             "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
251
 
             src, dst,gw_src,gw_dst);
252
 
  parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
253
 
}
254
 
/**
255
 
 * \brief Set a new link on the actual list of link for a route or ASroute from XML
256
 
 */
257
 
 
258
 
static void routing_parse_link_ctn(void)
259
 
{
260
 
  char *link_id;
261
 
  switch (A_surfxml_link_ctn_direction) {
262
 
  case AU_surfxml_link_ctn_direction:
263
 
  case A_surfxml_link_ctn_direction_NONE:
264
 
    link_id = xbt_strdup(A_surfxml_link_ctn_id);
265
 
    break;
266
 
  case A_surfxml_link_ctn_direction_UP:
267
 
    link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
268
 
    break;
269
 
  case A_surfxml_link_ctn_direction_DOWN:
270
 
    link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
271
 
    break;
272
 
  }
273
 
  xbt_dynar_push(parsed_link_list, &link_id);
274
 
}
275
 
 
276
222
/**
277
223
 * \brief Store the route by calling the set_route function of the current routing component
278
224
 */
279
 
static void routing_parse_E_route(void)
 
225
static void parse_E_route(sg_platf_route_cbarg_t route)
280
226
{
281
 
  route_t route = xbt_new0(s_route_t, 1);
282
 
  route->link_list = parsed_link_list;
283
227
  xbt_assert(current_routing->parse_route,
284
228
             "no defined method \"set_route\" in \"%s\"",
285
229
             current_routing->name);
286
 
  current_routing->parse_route(current_routing, src, dst, route);
287
 
  generic_free_route(route);
288
 
  parsed_link_list = NULL;
289
 
  src = NULL;
290
 
  dst = NULL;
 
230
 
 
231
  current_routing->parse_route(current_routing, route);
291
232
}
292
233
 
293
234
/**
294
235
 * \brief Store the ASroute by calling the set_ASroute function of the current routing component
295
236
 */
296
 
static void routing_parse_E_ASroute(void)
 
237
static void parse_E_ASroute(sg_platf_route_cbarg_t ASroute)
297
238
{
298
 
  route_t e_route = xbt_new0(s_route_t, 1);
299
 
  e_route->link_list = parsed_link_list;
300
 
 
301
 
  if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
302
 
    // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
303
 
    // store the provided name instead of the entity directly (model_rulebased_parse_ASroute knows)
304
 
    //
305
 
    // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
306
 
    e_route->src_gateway = (sg_routing_edge_t) gw_src;
307
 
    e_route->dst_gateway = (sg_routing_edge_t) gw_dst;
308
 
  } else {
309
 
    e_route->src_gateway = sg_routing_edge_by_name_or_null(gw_src);
310
 
    e_route->dst_gateway = sg_routing_edge_by_name_or_null(gw_dst);
311
 
  }
312
239
  xbt_assert(current_routing->parse_ASroute,
313
240
             "no defined method \"set_ASroute\" in \"%s\"",
314
241
             current_routing->name);
315
 
  current_routing->parse_ASroute(current_routing, src, dst, e_route);
316
 
  generic_free_route(e_route);
317
 
  parsed_link_list = NULL;
318
 
  src = NULL;
319
 
  dst = NULL;
320
 
  gw_src = NULL;
321
 
  gw_dst = NULL;
322
 
}
323
 
 
324
 
/**
325
 
 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
326
 
 */
327
 
static void routing_parse_E_bypassRoute(void)
328
 
{
329
 
  route_t e_route = xbt_new0(s_route_t, 1);
330
 
  e_route->link_list = parsed_link_list;
331
 
 
332
 
  xbt_assert(current_routing->parse_bypassroute,
333
 
             "Bypassing mechanism not implemented by routing '%s'",
334
 
             current_routing->name);
335
 
 
336
 
  current_routing->parse_bypassroute(current_routing, src, dst, e_route);
337
 
  parsed_link_list = NULL;
338
 
  src = NULL;
339
 
  dst = NULL;
340
 
  gw_src = NULL;
341
 
  gw_dst = NULL;
342
 
}
343
 
/**
344
 
 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
345
 
 */
346
 
static void routing_parse_E_bypassASroute(void)
347
 
{
348
 
  route_t e_route = xbt_new0(s_route_t, 1);
349
 
  e_route->link_list = parsed_link_list;
350
 
  e_route->src_gateway = sg_routing_edge_by_name_or_null(gw_src);
351
 
  e_route->dst_gateway = sg_routing_edge_by_name_or_null(gw_dst);
352
 
  xbt_assert(current_routing->parse_bypassroute,
353
 
             "Bypassing mechanism not implemented by routing '%s'",
354
 
             current_routing->name);
355
 
  current_routing->parse_bypassroute(current_routing, src, dst, e_route);
356
 
  parsed_link_list = NULL;
357
 
  src = NULL;
358
 
  dst = NULL;
359
 
  gw_src = NULL;
360
 
  gw_dst = NULL;
361
 
}
 
242
  current_routing->parse_ASroute(current_routing, ASroute);
 
243
}
 
244
 
 
245
/**
 
246
 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
 
247
 */
 
248
static void parse_E_bypassRoute(sg_platf_route_cbarg_t route)
 
249
{
 
250
  xbt_assert(current_routing->parse_bypassroute,
 
251
             "Bypassing mechanism not implemented by routing '%s'",
 
252
             current_routing->name);
 
253
 
 
254
  current_routing->parse_bypassroute(current_routing, route);
 
255
}
 
256
 
 
257
/**
 
258
 * \brief Store the bypass route by calling the set_bypassroute function of the current routing component
 
259
 */
 
260
static void parse_E_bypassASroute(sg_platf_route_cbarg_t ASroute)
 
261
{
 
262
  xbt_assert(current_routing->parse_bypassroute,
 
263
             "Bypassing mechanism not implemented by routing '%s'",
 
264
             current_routing->name);
 
265
  current_routing->parse_bypassroute(current_routing, ASroute);
 
266
}
 
267
 
 
268
static void routing_parse_trace(sg_platf_trace_cbarg_t trace)
 
269
{
 
270
  tmgr_trace_t tmgr_trace;
 
271
  if (!trace->file || strcmp(trace->file, "") != 0) {
 
272
    tmgr_trace = tmgr_trace_new_from_file(trace->file);
 
273
  } else if (strcmp(trace->pc_data, "") == 0) {
 
274
    tmgr_trace = NULL;
 
275
  } else {
 
276
    tmgr_trace =
 
277
          tmgr_trace_new_from_string(trace->id, trace->pc_data,
 
278
                                     trace->periodicity);
 
279
  }
 
280
  xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL);
 
281
}
 
282
 
 
283
static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect)
 
284
{
 
285
  xbt_assert(xbt_dict_get_or_null
 
286
              (traces_set_list, trace_connect->trace),
 
287
              "Cannot connect trace %s to %s: trace unknown",
 
288
              trace_connect->trace,
 
289
              trace_connect->element);
 
290
 
 
291
  switch (trace_connect->kind) {
 
292
  case SURF_TRACE_CONNECT_KIND_HOST_AVAIL:
 
293
    xbt_dict_set(trace_connect_list_host_avail,
 
294
        trace_connect->trace,
 
295
        xbt_strdup(trace_connect->element), NULL);
 
296
    break;
 
297
  case SURF_TRACE_CONNECT_KIND_POWER:
 
298
    xbt_dict_set(trace_connect_list_power, trace_connect->trace,
 
299
        xbt_strdup(trace_connect->element), NULL);
 
300
    break;
 
301
  case SURF_TRACE_CONNECT_KIND_LINK_AVAIL:
 
302
    xbt_dict_set(trace_connect_list_link_avail,
 
303
        trace_connect->trace,
 
304
        xbt_strdup(trace_connect->element), NULL);
 
305
    break;
 
306
  case SURF_TRACE_CONNECT_KIND_BANDWIDTH:
 
307
    xbt_dict_set(trace_connect_list_bandwidth,
 
308
        trace_connect->trace,
 
309
        xbt_strdup(trace_connect->element), NULL);
 
310
    break;
 
311
  case SURF_TRACE_CONNECT_KIND_LATENCY:
 
312
    xbt_dict_set(trace_connect_list_latency, trace_connect->trace,
 
313
        xbt_strdup(trace_connect->element), NULL);
 
314
    break;
 
315
  default:
 
316
    xbt_die("Cannot connect trace %s to %s: kind of trace unknown",
 
317
        trace_connect->trace, trace_connect->element);
 
318
    break;
 
319
  }
 
320
}
 
321
 
 
322
extern int _sg_init_status; /* yay, this is an horrible hack */
362
323
 
363
324
/**
364
325
 * \brief Make a new routing component to the platform
373
334
 * @param AS_id name of this autonomous system. Must be unique in the platform
374
335
 * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
375
336
 */
376
 
void routing_AS_begin(const char *AS_id, const char *wanted_routing_type)
 
337
void routing_AS_begin(sg_platf_AS_cbarg_t AS)
377
338
{
 
339
  XBT_DEBUG("routing_AS_begin");
378
340
  AS_t new_as;
379
341
  routing_model_description_t model = NULL;
380
 
  int cpt;
381
342
 
382
343
  xbt_assert(!xbt_lib_get_or_null
383
 
             (as_router_lib, AS_id, ROUTING_ASR_LEVEL),
384
 
             "The AS \"%s\" already exists", AS_id);
 
344
             (as_router_lib, AS->id, ROUTING_ASR_LEVEL),
 
345
             "The AS \"%s\" already exists", AS->id);
 
346
 
 
347
  _sg_init_status = 2; /* horrible hack: direct access to the global controlling the level of configuration to prevent any further config */
385
348
 
386
349
  /* search the routing model */
387
 
  for (cpt = 0; routing_models[cpt].name; cpt++)
388
 
    if (!strcmp(wanted_routing_type, routing_models[cpt].name))
389
 
      model = &routing_models[cpt];
390
 
  /* if its not exist, error */
391
 
  if (model == NULL) {
392
 
    fprintf(stderr, "Routing model %s not found. Existing models:\n",
393
 
            wanted_routing_type);
394
 
    for (cpt = 0; routing_models[cpt].name; cpt++)
395
 
      fprintf(stderr, "   %s: %s\n", routing_models[cpt].name,
396
 
              routing_models[cpt].desc);
397
 
    xbt_die("dying");
 
350
  switch(AS->routing){
 
351
    case A_surfxml_AS_routing_Cluster:       model = &routing_models[SURF_MODEL_CLUSTER];break;
 
352
    case A_surfxml_AS_routing_Dijkstra:      model = &routing_models[SURF_MODEL_DIJKSTRA];break;
 
353
    case A_surfxml_AS_routing_DijkstraCache: model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break;
 
354
    case A_surfxml_AS_routing_Floyd:         model = &routing_models[SURF_MODEL_FLOYD];break;
 
355
    case A_surfxml_AS_routing_Full:          model = &routing_models[SURF_MODEL_FULL];break;
 
356
    case A_surfxml_AS_routing_None:          model = &routing_models[SURF_MODEL_NONE];break;
 
357
    case A_surfxml_AS_routing_RuleBased:     model = &routing_models[SURF_MODEL_RULEBASED];break;
 
358
    case A_surfxml_AS_routing_Vivaldi:       model = &routing_models[SURF_MODEL_VIVALDI];break;
 
359
    default: xbt_die("Not a valid model!!!");
 
360
    break;
398
361
  }
399
362
 
400
363
  /* make a new routing component */
401
364
  new_as = (AS_t) model->create();
402
365
  new_as->model_desc = model;
403
366
  new_as->hierarchy = SURF_ROUTING_NULL;
404
 
  new_as->name = xbt_strdup(AS_id);
 
367
  new_as->name = xbt_strdup(AS->id);
405
368
 
406
369
  sg_routing_edge_t info = NULL;
407
 
  info = xbt_new0(s_network_element_t, 1);
 
370
  info = xbt_new0(s_routing_edge_t, 1);
408
371
 
409
372
  if (current_routing == NULL && routing_platf->root == NULL) {
410
373
 
415
378
  } else if (current_routing != NULL && routing_platf->root != NULL) {
416
379
 
417
380
    xbt_assert(!xbt_dict_get_or_null
418
 
               (current_routing->routing_sons, AS_id),
419
 
               "The AS \"%s\" already exists", AS_id);
 
381
               (current_routing->routing_sons, AS->id),
 
382
               "The AS \"%s\" already exists", AS->id);
420
383
    /* it is a part of the tree */
421
384
    new_as->routing_father = current_routing;
422
385
    /* set the father behavior */
423
386
    if (current_routing->hierarchy == SURF_ROUTING_NULL)
424
387
      current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
425
388
    /* add to the sons dictionary */
426
 
    xbt_dict_set(current_routing->routing_sons, AS_id,
 
389
    xbt_dict_set(current_routing->routing_sons, AS->id,
427
390
                 (void *) new_as, NULL);
428
391
    /* add to the father element list */
429
392
    info->id = current_routing->parse_AS(current_routing, (void *) info);
435
398
  info->rc_type = SURF_NETWORK_ELEMENT_AS;
436
399
  info->name = new_as->name;
437
400
 
438
 
  xbt_lib_set(as_router_lib, new_as->name, ROUTING_ASR_LEVEL,
 
401
  xbt_lib_set(as_router_lib, info->name, ROUTING_ASR_LEVEL,
439
402
              (void *) info);
440
403
  XBT_DEBUG("Having set name '%s' id '%d'",new_as->name,info->id);
441
404
 
456
419
 * even if you add stuff to a closed AS
457
420
 *
458
421
 */
459
 
void routing_AS_end()
 
422
void routing_AS_end(sg_platf_AS_cbarg_t AS)
460
423
{
461
424
 
462
425
  if (current_routing == NULL) {
557
520
static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
558
521
                                   xbt_dynar_t * links, double *latency)
559
522
{
560
 
  s_route_t route;
 
523
  s_sg_platf_route_cbarg_t route;
561
524
  memset(&route,0,sizeof(route));
562
525
 
 
526
  xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
563
527
  XBT_DEBUG("Solve route/latency  \"%s\" to \"%s\"", src->name, dst->name);
564
 
  xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
565
528
 
566
529
  /* Find how src and dst are interconnected */
567
530
  AS_t common_father, src_father, dst_father;
570
533
      common_father->name,src_father->name,dst_father->name);
571
534
 
572
535
  /* Check whether a direct bypass is defined */
573
 
  route_t e_route_bypass = NULL;
 
536
  sg_platf_route_cbarg_t e_route_bypass = NULL;
574
537
  if (common_father->get_bypass_route)
575
538
    e_route_bypass = common_father->get_bypass_route(common_father, src, dst, latency);
576
539
 
585
548
  if (src_father == dst_father) {       /* SURF_ROUTING_BASE */
586
549
    route.link_list = *links;
587
550
    common_father->get_route_and_latency(common_father, src, dst, &route,latency);
 
551
    // if vivaldi latency+=vivaldi(src,dst)
588
552
    return;
589
553
  }
590
554
 
599
563
                                       src_father_net_elm, dst_father_net_elm,
600
564
                                       &route, latency);
601
565
 
602
 
  xbt_assert((route.src_gateway != NULL) && (route.dst_gateway != NULL),
 
566
  xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
603
567
      "bad gateways for route from \"%s\" to \"%s\"", src->name, dst->name);
604
568
 
605
 
  sg_routing_edge_t src_gateway_net_elm = route.src_gateway;
606
 
  sg_routing_edge_t dst_gateway_net_elm = route.dst_gateway;
 
569
  sg_routing_edge_t src_gateway_net_elm = route.gw_src;
 
570
  sg_routing_edge_t dst_gateway_net_elm = route.gw_dst;
607
571
 
608
572
  /* If source gateway is not our source, we have to recursively find our way up to this point */
609
573
  if (src != src_gateway_net_elm)
610
574
    _get_route_and_latency(src, src_gateway_net_elm, links, latency);
611
 
 
612
575
  xbt_dynar_merge(links, &route.link_list);
613
576
 
614
577
  /* If dest gateway is not our destination, we have to recursively find our way from this point */
615
578
  if (dst_gateway_net_elm != dst)
616
579
    _get_route_and_latency(dst_gateway_net_elm, dst, links, latency);
 
580
 
 
581
  // if vivaldi latency+=vivaldi(src_gateway,dst_gateway)
617
582
}
618
583
 
619
584
/**
745
710
/* ************************************************************************** */
746
711
/* ************************* GENERIC PARSE FUNCTIONS ************************ */
747
712
 
 
713
void routing_cluster_add_backbone(void* bb) {
 
714
  xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER],
 
715
        "You have to be in model Cluster to use tag backbone!");
 
716
  xbt_assert(!((as_cluster_t)current_routing)->backbone,"The backbone link is already defined!");
 
717
  ((as_cluster_t)current_routing)->backbone = bb;
 
718
  XBT_DEBUG("Add a backbone to AS '%s'",current_routing->name);
 
719
}
 
720
 
 
721
static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
 
722
{
 
723
  int start, end, i;
 
724
  char *groups , *host_id , *link_id = NULL;
 
725
  unsigned int iter;
 
726
  xbt_dynar_t radical_elements;
 
727
  xbt_dynar_t radical_ends;
 
728
 
 
729
  //Make all hosts
 
730
  radical_elements = xbt_str_split(cabinet->radical, ",");
 
731
  xbt_dynar_foreach(radical_elements, iter, groups) {
 
732
 
 
733
    radical_ends = xbt_str_split(groups, "-");
 
734
    start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
 
735
 
 
736
    switch (xbt_dynar_length(radical_ends)) {
 
737
    case 1:
 
738
      end = start;
 
739
      break;
 
740
    case 2:
 
741
      end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
 
742
      break;
 
743
    default:
 
744
      surf_parse_error("Malformed radical");
 
745
      break;
 
746
    }
 
747
    s_sg_platf_host_cbarg_t host;
 
748
    memset(&host, 0, sizeof(host));
 
749
    host.initial_state = SURF_RESOURCE_ON;
 
750
    host.power_peak = cabinet->power;
 
751
    host.power_scale = 1.0;
 
752
    host.core_amount = 1;
 
753
 
 
754
    s_sg_platf_link_cbarg_t link;
 
755
    memset(&link, 0, sizeof(link));
 
756
    link.state = SURF_RESOURCE_ON;
 
757
    link.policy = SURF_LINK_FULLDUPLEX;
 
758
    link.latency = cabinet->lat;
 
759
    link.bandwidth = cabinet->bw;
 
760
 
 
761
    s_sg_platf_host_link_cbarg_t host_link;
 
762
    memset(&host_link, 0, sizeof(host_link));
 
763
 
 
764
    for (i = start; i <= end; i++) {
 
765
      host_id = bprintf("%s%d%s",cabinet->prefix,i,cabinet->suffix);
 
766
      link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix);
 
767
      host.id = host_id;
 
768
      link.id = link_id;
 
769
      sg_platf_new_host(&host);
 
770
      sg_platf_new_link(&link);
 
771
 
 
772
      char* link_up = bprintf("%s_UP",link_id);
 
773
      char* link_down = bprintf("%s_DOWN",link_id);
 
774
      host_link.id = host_id;
 
775
      host_link.link_up = link_up;
 
776
      host_link.link_down= link_down;
 
777
      sg_platf_new_host_link(&host_link);
 
778
 
 
779
      free(host_id);
 
780
      free(link_id);
 
781
      free(link_up);
 
782
      free(link_down);
 
783
    }
 
784
 
 
785
    xbt_dynar_free(&radical_ends);
 
786
  }
 
787
  xbt_dynar_free(&radical_elements);
 
788
}
 
789
 
748
790
static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
749
791
{
750
792
  char *host_id, *groups, *link_id = NULL;
758
800
  xbt_dynar_t radical_elements;
759
801
  xbt_dynar_t radical_ends;
760
802
 
761
 
  if (strcmp(cluster->availability_trace, "")
762
 
      || strcmp(cluster->state_trace, "")) {
 
803
  if ((cluster->availability_trace && strcmp(cluster->availability_trace, ""))
 
804
      || (cluster->state_trace && strcmp(cluster->state_trace, ""))) {
763
805
    patterns = xbt_dict_new_homogeneous(xbt_free_f);
764
806
    xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL);
765
807
    xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL);
767
809
  }
768
810
 
769
811
  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", cluster->id);
770
 
  sg_platf_new_AS_begin(cluster->id, "Cluster");
 
812
  s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
 
813
  AS.id = cluster->id;
 
814
  AS.routing = A_surfxml_AS_routing_Cluster;
 
815
  sg_platf_new_AS_begin(&AS);
771
816
 
772
817
  current_routing->link_up_down_list
773
818
            = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
799
844
 
800
845
      memset(&host, 0, sizeof(host));
801
846
      host.id = host_id;
802
 
      if (strcmp(cluster->availability_trace, "")) {
 
847
      if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) {
803
848
        xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
804
849
        char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
805
850
        XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
806
 
        host.power_trace = tmgr_trace_new(avail_file);
 
851
        host.power_trace = tmgr_trace_new_from_file(avail_file);
807
852
        xbt_free(avail_file);
808
853
      } else {
809
854
        XBT_DEBUG("\tavailability_file=\"\"");
810
855
      }
811
856
 
812
 
      if (strcmp(cluster->state_trace, "")) {
 
857
      if (cluster->state_trace && strcmp(cluster->state_trace, "")) {
813
858
        char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
814
859
        XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
815
 
        host.state_trace = tmgr_trace_new(avail_file);
 
860
        host.state_trace = tmgr_trace_new_from_file(avail_file);
816
861
        xbt_free(avail_file);
817
862
      } else {
818
863
        XBT_DEBUG("\tstate_file=\"\"");
878
923
  free(newid);
879
924
 
880
925
  //Make the backbone
881
 
  if ((cluster->bb_bw != 0) && (cluster->bb_lat != 0)) {
 
926
  if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
882
927
    char *link_backbone = bprintf("%s_backbone", cluster->id);
883
928
    XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,
884
929
              cluster->bb_bw, cluster->bb_lat);
892
937
 
893
938
    sg_platf_new_link(&link);
894
939
 
895
 
    surf_routing_cluster_add_backbone(current_routing, xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL));
 
940
    routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL));
896
941
 
897
942
    free(link_backbone);
898
943
  }
909
954
 
910
955
static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
911
956
{
912
 
  static int AX_ptr = 0;
913
957
  char *host_id = NULL;
914
 
  char *router_id, *link_router, *link_backbone, *link_id_up, *link_id_down;
915
 
 
916
 
  static unsigned int surfxml_buffer_stack_stack_ptr = 1;
917
 
  static unsigned int surfxml_buffer_stack_stack[1024];
918
 
 
919
 
  surfxml_buffer_stack_stack[0] = 0;
920
 
 
921
 
  surfxml_bufferstack_push(1);
922
 
 
923
 
  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer->id);
924
 
  sg_platf_new_AS_begin(peer->id, "Full");
 
958
  char *link_id;
925
959
 
926
960
  XBT_DEBUG(" ");
927
961
  host_id = HOST_PEER(peer->id);
928
 
  router_id = ROUTER_PEER(peer->id);
929
 
  link_id_up = LINK_UP_PEER(peer->id);
930
 
  link_id_down = LINK_DOWN_PEER(peer->id);
931
 
 
932
 
  link_router = bprintf("%s_link_router", peer->id);
933
 
  link_backbone = bprintf("%s_backbone", peer->id);
 
962
  link_id = LINK_PEER(peer->id);
934
963
 
935
964
  XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->power);
936
965
  s_sg_platf_host_cbarg_t host;
945
974
  host.coord = peer->coord;
946
975
  sg_platf_new_host(&host);
947
976
 
948
 
 
949
 
  XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer->coord);
950
 
  s_sg_platf_router_cbarg_t router;
951
 
  memset(&router, 0, sizeof(router));
952
 
  router.id = router_id;
953
 
  router.coord = peer->coord;
954
 
  sg_platf_new_router(&router);
955
 
 
956
 
  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id_up,
957
 
            peer->bw_in, peer->lat);
958
977
  s_sg_platf_link_cbarg_t link;
959
978
  memset(&link, 0, sizeof(link));
960
979
  link.state = SURF_RESOURCE_ON;
961
980
  link.policy = SURF_LINK_SHARED;
962
 
  link.id = link_id_up;
963
 
  link.bandwidth = peer->bw_in;
964
981
  link.latency = peer->lat;
965
 
  sg_platf_new_link(&link);
966
982
 
967
 
  // FIXME: dealing with full duplex is not the role of this piece of code, I'd say [Mt]
968
 
  // Instead, it should be created fullduplex, and the models will do what's needed in this case
969
 
  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id_down,
 
983
  char* link_up = bprintf("%s_UP",link_id);
 
984
  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_up,
970
985
            peer->bw_out, peer->lat);
971
 
  link.id = link_id_down;
972
 
  sg_platf_new_link(&link);
973
 
 
974
 
  XBT_DEBUG(" ");
975
 
 
976
 
  // begin here
977
 
  XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", host_id, router_id);
978
 
  XBT_DEBUG("symmetrical=\"NO\">");
979
 
  SURFXML_BUFFER_SET(route_src, host_id);
980
 
  SURFXML_BUFFER_SET(route_dst, router_id);
981
 
  A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
982
 
  SURFXML_START_TAG(route);
983
 
 
984
 
  XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_up);
985
 
  SURFXML_BUFFER_SET(link_ctn_id, link_id_up);
986
 
  A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
987
 
  SURFXML_START_TAG(link_ctn);
988
 
  SURFXML_END_TAG(link_ctn);
989
 
 
990
 
  XBT_DEBUG("</route>");
991
 
  SURFXML_END_TAG(route);
992
 
 
993
 
  //Opposite Route
994
 
  XBT_DEBUG("<route\tsrc=\"%s\"\tdst=\"%s\"", router_id, host_id);
995
 
  XBT_DEBUG("symmetrical=\"NO\">");
996
 
  SURFXML_BUFFER_SET(route_src, router_id);
997
 
  SURFXML_BUFFER_SET(route_dst, host_id);
998
 
  A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
999
 
  SURFXML_START_TAG(route);
1000
 
 
1001
 
  XBT_DEBUG("<link_ctn\tid=\"%s\"/>", link_id_down);
1002
 
  SURFXML_BUFFER_SET(link_ctn_id, link_id_down);
1003
 
  A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
1004
 
  SURFXML_START_TAG(link_ctn);
1005
 
  SURFXML_END_TAG(link_ctn);
1006
 
 
1007
 
  XBT_DEBUG("</route>");
1008
 
  SURFXML_END_TAG(route);
1009
 
 
1010
 
  XBT_DEBUG("</AS>");
1011
 
  sg_platf_new_AS_end();
 
986
  link.id = link_up;
 
987
  link.bandwidth = peer->bw_out;
 
988
  sg_platf_new_link(&link);
 
989
 
 
990
  char* link_down = bprintf("%s_DOWN",link_id);
 
991
  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_down,
 
992
            peer->bw_in, peer->lat);
 
993
  link.id = link_down;
 
994
  link.bandwidth = peer->bw_in;
 
995
  sg_platf_new_link(&link);
 
996
 
 
997
  XBT_DEBUG("<host_link\tid=\"%s\"\tup=\"%s\"\tdown=\"%s\" />", host_id,link_up,link_down);
 
998
  s_sg_platf_host_link_cbarg_t host_link;
 
999
  memset(&host_link, 0, sizeof(host_link));
 
1000
  host_link.id = host_id;
 
1001
  host_link.link_up = link_up;
 
1002
  host_link.link_down= link_down;
 
1003
  sg_platf_new_host_link(&host_link);
 
1004
 
1012
1005
  XBT_DEBUG(" ");
1013
1006
 
1014
1007
  //xbt_dynar_free(&tab_elements_num);
1015
1008
  free(host_id);
1016
 
  free(router_id);
1017
 
  free(link_router);
1018
 
  free(link_backbone);
1019
 
  free(link_id_up);
1020
 
  free(link_id_down);
1021
 
  surfxml_bufferstack_pop(1);
 
1009
  free(link_id);
 
1010
  free(link_up);
 
1011
  free(link_down);
1022
1012
}
1023
1013
 
1024
1014
static void routing_parse_Srandom(void)
1029
1019
  char *rd_name = NULL;
1030
1020
  char *rd_value;
1031
1021
  mean = surf_parse_get_double(A_surfxml_random_mean);
1032
 
  std = surf_parse_get_double(A_surfxml_random_std_deviation);
 
1022
  std = surf_parse_get_double(A_surfxml_random_std___deviation);
1033
1023
  min = surf_parse_get_double(A_surfxml_random_min);
1034
1024
  max = surf_parse_get_double(A_surfxml_random_max);
1035
1025
  seed = surf_parse_get_double(A_surfxml_random_seed);
1145
1135
{
1146
1136
  sg_platf_host_add_cb(parse_S_host);
1147
1137
  sg_platf_router_add_cb(parse_S_router);
1148
 
 
1149
 
  surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);
1150
 
 
1151
 
  surfxml_add_callback(STag_surfxml_route_cb_list, &routing_parse_S_route);
1152
 
  surfxml_add_callback(STag_surfxml_ASroute_cb_list, &routing_parse_S_ASroute);
1153
 
  surfxml_add_callback(STag_surfxml_bypassRoute_cb_list,
1154
 
                       &routing_parse_S_bypassRoute);
1155
 
  surfxml_add_callback(STag_surfxml_bypassASroute_cb_list,
1156
 
                       &routing_parse_S_bypassASroute);
1157
 
 
1158
 
  surfxml_add_callback(ETag_surfxml_link_ctn_cb_list, &routing_parse_link_ctn);
1159
 
 
1160
 
  surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_parse_E_route);
1161
 
  surfxml_add_callback(ETag_surfxml_ASroute_cb_list, &routing_parse_E_ASroute);
1162
 
  surfxml_add_callback(ETag_surfxml_bypassRoute_cb_list,
1163
 
                       &routing_parse_E_bypassRoute);
1164
 
  surfxml_add_callback(ETag_surfxml_bypassASroute_cb_list,
1165
 
                       &routing_parse_E_bypassASroute);
 
1138
  sg_platf_host_link_add_cb(parse_S_host_link);
 
1139
  sg_platf_route_add_cb(parse_E_route);
 
1140
  sg_platf_ASroute_add_cb(parse_E_ASroute);
 
1141
  sg_platf_bypassRoute_add_cb(parse_E_bypassRoute);
 
1142
  sg_platf_bypassASroute_add_cb(parse_E_bypassASroute);
1166
1143
 
1167
1144
  sg_platf_cluster_add_cb(routing_parse_cluster);
 
1145
  sg_platf_cabinet_add_cb(routing_parse_cabinet);
1168
1146
 
1169
1147
  sg_platf_peer_add_cb(routing_parse_peer);
1170
1148
  sg_platf_postparse_add_cb(routing_parse_postparse);
1173
1151
  sg_platf_AS_end_add_cb(routing_AS_end);
1174
1152
  sg_platf_AS_begin_add_cb(routing_AS_begin);
1175
1153
 
 
1154
  sg_platf_trace_add_cb(routing_parse_trace);
 
1155
  sg_platf_trace_connect_add_cb(routing_parse_trace_connect);
 
1156
 
1176
1157
#ifdef HAVE_TRACING
1177
1158
  instr_routing_define_callbacks();
1178
1159
#endif