Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
153be093f943a6ceadb68087007b48ac57ad4e8e
[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/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   for (auto card : vertices_) {
27     s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
28     if (host != nullptr)
29       hosts_->push_back(host);
30   }
31 }
32
33 void NetZone::seal()
34 {
35   sealed_ = true;
36 }
37 NetZone::~NetZone()
38 {
39   xbt_dict_cursor_t cursor = nullptr;
40   char* key;
41   NetZone* elem;
42   xbt_dict_foreach (children_, cursor, key, elem) {
43     delete static_cast<NetZone*>(elem);
44   }
45
46   xbt_dict_free(&children_);
47   xbt_free(name_);
48 }
49 std::unordered_map<std::string, std::string>* NetZone::properties()
50 {
51   return simgrid::simix::kernelImmediate([this] {
52       return &properties_;
53   });
54 }
55
56 /** Retrieve the property value (or nullptr if not set) */
57 const char* NetZone::property(const char* key)
58 {
59   return properties_.at(key).c_str();
60 }
61 void NetZone::setProperty(const char* key, const char* value)
62 {
63   simgrid::simix::kernelImmediate([this,key,value] {
64     properties_[key] = value;
65   });
66 }
67
68 xbt_dict_t NetZone::children()
69 {
70   return children_;
71 }
72 char* NetZone::name()
73 {
74   return name_;
75 }
76 NetZone* NetZone::father()
77 {
78   return father_;
79 }
80
81 std::vector<s4u::Host*>* NetZone::hosts()
82 {
83   return hosts_;
84 }
85
86 int NetZone::addComponent(kernel::routing::NetPoint* elm)
87 {
88   vertices_.push_back(elm);
89   return vertices_.size() - 1; // The rank of the newly created object
90 }
91
92 void NetZone::addRoute(sg_platf_route_cbarg_t /*route*/)
93 {
94   xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_);
95 }
96 }
97 }; // namespace simgrid::s4u