Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / s4u / s4u_netzone.cpp
1 /* Copyright (c) 2006-2017. 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/Host.hpp"
9 #include "simgrid/s4u/NetZone.hpp"
10 #include "simgrid/simix.hpp"
11 #include "src/kernel/routing/NetPoint.hpp"
12 #include "src/surf/network_interface.hpp" // Link FIXME: move to proper header
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_netzone, "S4U Networking Zones");
15
16 namespace simgrid {
17 namespace s4u {
18
19 simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
20                           kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
21                           std::vector<surf::LinkImpl*>* link_list)>
22     NetZone::onRouteCreation;
23
24 NetZone::NetZone(NetZone* father, const char* name) : father_(father), name_(xbt_strdup(name))
25 {
26   children_ = new std::vector<NetZone*>();
27 }
28
29 void NetZone::seal()
30 {
31   sealed_ = true;
32 }
33
34 NetZone::~NetZone()
35 {
36   for (auto nz : *children_)
37     delete nz;
38   delete children_;
39   xbt_free(name_);
40 }
41
42 std::unordered_map<std::string, std::string>* NetZone::properties()
43 {
44   return simgrid::simix::kernelImmediate([this] {
45       return &properties_;
46   });
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([this,key,value] {
57     properties_[key] = value;
58   });
59 }
60
61 std::vector<NetZone*>* NetZone::children()
62 {
63   return children_;
64 }
65 char* NetZone::name()
66 {
67   return name_;
68 }
69 NetZone* NetZone::father()
70 {
71   return father_;
72 }
73
74 std::vector<s4u::Host*>* NetZone::hosts()
75 {
76   if (hosts_.empty()) // Lazy initialization
77     for (auto card : vertices_) {
78       s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
79       if (host != nullptr)
80         hosts_.push_back(host);
81     }
82   return &hosts_;
83 }
84
85 int NetZone::addComponent(kernel::routing::NetPoint* elm)
86 {
87   vertices_.push_back(elm);
88   return vertices_.size() - 1; // The rank of the newly created object
89 }
90
91 void NetZone::addRoute(sg_platf_route_cbarg_t /*route*/)
92 {
93   xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_);
94 }
95 }
96 }; // namespace simgrid::s4u