Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
actually, BypassRoute can be made private to AsImpl
[simgrid.git] / src / s4u / s4u_as.cpp
1 /* Copyright (c) 2006-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <xbt/log.h>
8
9 #include <simgrid/s4u/host.hpp>
10 #include <simgrid/s4u/As.hpp>
11
12 #include "src/kernel/routing/NetCard.hpp"
13 #include "src/surf/network_interface.hpp" // Link FIXME: move to proper header
14 #include "src/surf/surf_routing.hpp"
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_as,"S4U autonomous systems");
17
18 namespace simgrid {
19   namespace s4u {
20
21   simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetCard* src, kernel::routing::NetCard* dst,
22                             kernel::routing::NetCard* gw_src, kernel::routing::NetCard* gw_dst,
23                             std::vector<Link*>* link_list)>
24       As::onRouteCreation;
25
26   As::As(As* father, const char* name) : father_(father), name_(xbt_strdup(name))
27   {
28   }
29   void As::seal()
30   {
31     sealed_ = true;
32   }
33   As::~As()
34   {
35     xbt_dict_cursor_t cursor = nullptr;
36     char* key;
37     AS_t elem;
38     xbt_dict_foreach(children_, cursor, key, elem) { delete (As*)elem; }
39
40     xbt_dict_free(&children_);
41     xbt_free(name_);
42   }
43
44   xbt_dict_t As::children()
45   {
46     return children_;
47   }
48   char* As::name()
49   {
50     return name_;
51   }
52   As* As::father()
53   {
54     return father_;
55   }
56
57   xbt_dynar_t As::hosts()
58   {
59     xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
60
61     for (auto card : vertices_) {
62       s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
63       if (host != nullptr)
64         xbt_dynar_push(res, &host);
65     }
66     return res;
67   }
68
69   int As::addComponent(kernel::routing::NetCard* elm)
70   {
71     vertices_.push_back(elm);
72     return vertices_.size() - 1; // The rank of the newly created object
73   }
74
75   void As::addRoute(sg_platf_route_cbarg_t /*route*/)
76   {
77     xbt_die("AS %s does not accept new routes (wrong class).", name_);
78   }
79
80 }  }; // namespace simgrid::s4u