Logo AND Algorithmique Numérique Distribuée

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