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 simgrid::xbt::signal<void(NetZone&)> NetZone::onCreation;
24 simgrid::xbt::signal<void(NetZone&)> NetZone::onSeal;
25
26 NetZone::NetZone(NetZone* father, std::string name) : father_(father), name_(name)
27 {
28   children_ = new std::vector<NetZone*>();
29 }
30
31 void NetZone::seal()
32 {
33   sealed_ = true;
34 }
35
36 NetZone::~NetZone()
37 {
38   for (auto const& nz : *children_)
39     delete nz;
40   delete children_;
41 }
42
43 std::unordered_map<std::string, std::string>* NetZone::getProperties()
44 {
45   return simgrid::simix::kernelImmediate([this] {
46       return &properties_;
47   });
48 }
49
50 /** Retrieve the property value (or nullptr if not set) */
51 const char* NetZone::getProperty(const char* key)
52 {
53   return properties_.at(key).c_str();
54 }
55 void NetZone::setProperty(const char* key, const char* value)
56 {
57   simgrid::simix::kernelImmediate([this,key,value] {
58     properties_[key] = value;
59   });
60 }
61
62 /** @brief Returns the list of direct children (no grand-children)
63  *
64  * This function returns the internal copy of the childrens, not a copy. Don't mess with it!
65  */
66 std::vector<NetZone*>* NetZone::getChildren()
67 {
68   return children_;
69 }
70
71 const char* NetZone::getCname() const
72 {
73   return name_.c_str();
74 }
75 NetZone* NetZone::getFather()
76 {
77   return father_;
78 }
79
80 void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
81 {
82   for (auto const& card : vertices_) {
83     s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->getName());
84     if (host != nullptr)
85       whereto->push_back(host);
86   }
87 }
88
89 int NetZone::getHostCount()
90 {
91   int count = 0;
92   for (auto const& card : vertices_) {
93     s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->getName());
94     if (host != nullptr)
95       count++;
96   }
97   return count;
98 }
99
100 int NetZone::addComponent(kernel::routing::NetPoint* elm)
101 {
102   vertices_.push_back(elm);
103   return vertices_.size() - 1; // The rank of the newly created object
104 }
105
106 void NetZone::addRoute(sg_netpoint_t /*src*/, sg_netpoint_t /*dst*/, sg_netpoint_t /*gw_src*/, sg_netpoint_t /*gw_dst*/,
107                        std::vector<simgrid::surf::LinkImpl*>& /*link_list*/, bool /*symmetrical*/)
108 {
109   xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str());
110 }
111 }
112 }; // namespace simgrid::s4u