Logo AND Algorithmique Numérique Distribuée

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