- MSG_storage_set_property_value()
* VM properties. Since msg_vm_t are msg_host_t, just use
MSG_host_get_property_value() and friends
+ * MSG_as_router_get_property_value() was redundent with
+ MSG_environment_as_get_property_value().
+ - Removed MSG_as_router_*propert*() functions
+ - Added MSG_environment_as_set_property_value() for consistency
* xbt heterogeneous dictionnaries (created with xbt_dict_new()).
Well, they are still there for now, but deprecated with a warning.
Please switch to xbt_dict_new_homogeneous() before this is removed
> [ 2.000000] (4:david@host2) == Print the properties of the host 'node-0.acme.org'
> [ 2.000000] (4:david@host2) Host property: 'mem' -> '42'
> [ 2.000000] (4:david@host2) Host property: 'bla' -> 'acme cluster'
-> [ 2.000000] (4:david@host2) Host property: 'name' -> 'AS2'
> [ 2.000000] (4:david@host2) Host property: 'Hdd' -> '180'
> [ 2.000000] (4:david@host2) == Try to get a host property that does not exist
> [ 2.000000] (4:david@host2) == Try to get a host property that does exist
XBT_PUBLIC(msg_netzone_t) MSG_environment_as_get_by_name(const char* name);
XBT_PUBLIC(xbt_dict_t) MSG_environment_as_get_routing_sons(msg_netzone_t as);
XBT_PUBLIC(const char*) MSG_environment_as_get_property_value(msg_netzone_t as, const char* name);
+XBT_PUBLIC(void) MSG_environment_as_set_property_value(const char* asr, const char* name, char* value);
XBT_PUBLIC(xbt_dynar_t) MSG_environment_as_get_hosts(msg_netzone_t as);
/************************** File handling ***********************************/
XBT_PUBLIC(sg_size_t) MSG_storage_get_size(msg_storage_t storage);
XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage);
-/************************** AS Router handling ************************************/
-XBT_PUBLIC(const char *) MSG_as_router_get_property_value(const char* asr, const char *name);
-XBT_PUBLIC(xbt_dict_t) MSG_as_router_get_properties(const char* asr);
-XBT_PUBLIC(void) MSG_as_router_set_property_value(const char* asr, const char* name, char* value);
/************************** Host handling ***********************************/
XBT_PUBLIC(msg_host_t) MSG_host_by_name(const char *name);
#ifndef SIMGRID_S4U_NETZONE_HPP
#define SIMGRID_S4U_NETZONE_HPP
-#include <map>
#include <string>
+#include <unordered_map>
#include <utility>
#include <vector>
xbt_dict_t children(); // Sub netzones
xbt_dynar_t hosts(); // my content as a dynar
+ /** Get the properties assigned to a host */
+ std::unordered_map<std::string, std::string>* properties();
+
+ /** Retrieve the property value (or nullptr if not set) */
+ const char* property(const char* key);
+ void setProperty(const char* key, const char* value);
+
/* Add content to the netzone, at parsing time. It should be sealed afterward. */
virtual int addComponent(kernel::routing::NetCard * elm); /* A host, a router or a netzone, whatever */
virtual void addRoute(sg_platf_route_cbarg_t route);
vertices_; // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
private:
+ std::unordered_map<std::string, std::string> properties_;
NetZone* father_ = nullptr;
char* name_ = nullptr;
XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_storage_t storage);
XBT_PUBLIC(sg_size_t) SIMIX_storage_get_size(smx_storage_t storage);
XBT_PUBLIC(const char*) SIMIX_storage_get_host(smx_storage_t storage);
-/************************** AS router **********************************/
-XBT_PUBLIC(xbt_dict_t) SIMIX_asr_get_properties(const char *name);
-/************************** AS router simcalls ***************************/
-XBT_PUBLIC(xbt_dict_t) simcall_asr_get_properties(const char *name);
/************************** MC simcalls **********************************/
XBT_PUBLIC(int) simcall_mc_random(int min, int max);
XBT_PUBLIC_DATA(xbt_lib_t) as_router_lib;
XBT_PUBLIC_DATA(int) ROUTING_ASR_LEVEL; //Routing level
-XBT_PUBLIC_DATA(int) ROUTING_PROP_ASR_LEVEL; //Properties for AS and router
XBT_PUBLIC_DATA(xbt_lib_t) storage_lib;
XBT_PUBLIC_DATA(int) ROUTING_STORAGE_LEVEL; //Routing storage level
/* For the trace and trace:connect tag (store their content till the end of the parsing) */
XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
-XBT_PUBLIC(xbt_dict_t) get_as_router_properties(const char* name);
-
/*
* Returns the initial path. On Windows the initial path is the current directory for the current process in the other
* case the function returns "./" that represents the current directory on Unix/Linux platforms.
#ifndef SIMGRID_ROUTING_NETZONEIMPL_HPP
#define SIMGRID_ROUTING_NETZONEIMPL_HPP
+#include <map>
+
#include "xbt/graph.h"
#include "simgrid/s4u/NetZone.hpp"
return simgrid::s4u::Engine::instance()->netRoot();
}
-const char* MSG_environment_as_get_name(msg_netzone_t as)
+const char* MSG_environment_as_get_name(msg_netzone_t netzone)
{
- return as->name();
+ return netzone->name();
}
msg_netzone_t MSG_environment_as_get_by_name(const char* name)
return simgrid::s4u::Engine::instance()->netzoneByNameOrNull(name);
}
-xbt_dict_t MSG_environment_as_get_routing_sons(msg_netzone_t as)
+xbt_dict_t MSG_environment_as_get_routing_sons(msg_netzone_t netzone)
{
- return as->children();
+ return netzone->children();
}
-const char* MSG_environment_as_get_property_value(msg_netzone_t as, const char* name)
+const char* MSG_environment_as_get_property_value(msg_netzone_t netzone, const char* name)
{
- xbt_dict_t dict = static_cast<xbt_dict_t> (xbt_lib_get_or_null(as_router_lib, MSG_environment_as_get_name(as),
- ROUTING_PROP_ASR_LEVEL));
- if (dict==nullptr)
- return nullptr;
- return static_cast<const char*>(xbt_dict_get_or_null(dict, name));
+ return netzone->property(name);
}
-xbt_dynar_t MSG_environment_as_get_hosts(msg_netzone_t as)
+void MSG_environment_as_set_property_value(msg_netzone_t netzone, const char* name, char* value)
{
- return as->hosts();
+ netzone->setProperty(name, value);
+}
+
+xbt_dynar_t MSG_environment_as_get_hosts(msg_netzone_t netzone)
+{
+ return netzone->hosts();
}
{
return task->category;
}
-
-/**
- * \brief Returns the value of a given AS or router property
- *
- * \param asr the name of a router or AS
- * \param name a property name
- * \return value of a property (or nullptr if property not set)
- */
-const char *MSG_as_router_get_property_value(const char* asr, const char *name)
-{
- return static_cast<char*>(xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name));
-}
-
-/**
- * \brief Returns a xbt_dict_t consisting of the list of properties assigned to
- * a the AS or router
- *
- * \param asr the name of a router or AS
- * \return a dict containing the properties
- */
-xbt_dict_t MSG_as_router_get_properties(const char* asr)
-{
- return (simcall_asr_get_properties(asr));
-}
-
-/**
- * \brief Change the value of a given AS or router
- *
- * \param asr the name of a router or AS
- * \param name a property name
- * \param value what to change the property to
- */
-void MSG_as_router_set_property_value(const char* asr, const char* name, char* value)
-{
- xbt_dict_set(MSG_as_router_get_properties(asr), name, value, nullptr);
-}
Host::Host(const char* name)
: name_(name)
{
- xbt_assert(sg_host_by_name(name) == nullptr, "Refusing to create a second host named '%s'.", name);
+ xbt_assert(Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name);
host_list[name_] = this;
}
#include "simgrid/s4u/NetZone.hpp"
#include "simgrid/s4u/host.hpp"
+#include "simgrid/simix.hpp"
#include "src/kernel/routing/NetCard.hpp"
#include "src/surf/network_interface.hpp" // Link FIXME: move to proper header
#include "src/surf/surf_routing.hpp"
xbt_dict_free(&children_);
xbt_free(name_);
}
+std::unordered_map<std::string, std::string>* NetZone::properties()
+{
+ return simgrid::simix::kernelImmediate([&] { return &properties_; });
+}
+
+/** Retrieve the property value (or nullptr if not set) */
+const char* NetZone::property(const char* key)
+{
+ return properties_.at(key).c_str();
+}
+void NetZone::setProperty(const char* key, const char* value)
+{
+ simgrid::simix::kernelImmediate([&] { properties_[key] = value; });
+}
xbt_dict_t NetZone::children()
{
}
}
-// ***** AS simcalls
-
-/**
- * \ingroup simix_host_management
- * \brief Returns a dict of the properties assigned to a router or AS.
- *
- * \param name The name of the router or AS
- * \return The properties
- */
-xbt_dict_t simcall_asr_get_properties(const char *name)
-{
- return simcall_BODY_asr_get_properties(name);
-}
-
/**
* \ingroup simix_process_management
* \brief Creates a synchro that executes some computation of an host.
simgrid::simix::marshal<xbt_dict_t>(simcall->result, result);
}
-static inline const char* simcall_asr_get_properties__get__name(smx_simcall_t simcall) {
- return simgrid::simix::unmarshal<const char*>(simcall->args[0]);
-}
-static inline void simcall_asr_get_properties__set__name(smx_simcall_t simcall, const char* arg) {
- simgrid::simix::marshal<const char*>(simcall->args[0], arg);
-}
-static inline xbt_dict_t simcall_asr_get_properties__get__result(smx_simcall_t simcall){
- return simgrid::simix::unmarshal<xbt_dict_t>(simcall->result);
-}
-static inline void simcall_asr_get_properties__set__result(smx_simcall_t simcall, xbt_dict_t result){
- simgrid::simix::marshal<xbt_dict_t>(simcall->result, result);
-}
-
static inline int simcall_mc_random__get__min(smx_simcall_t simcall) {
return simgrid::simix::unmarshal<int>(simcall->args[0]);
}
XBT_PRIVATE int simcall_HANDLER_file_move(smx_simcall_t simcall, smx_file_t fd, const char* fullpath);
XBT_PRIVATE sg_size_t simcall_HANDLER_storage_get_free_size(smx_simcall_t simcall, smx_storage_t storage);
XBT_PRIVATE sg_size_t simcall_HANDLER_storage_get_used_size(smx_simcall_t simcall, smx_storage_t name);
-XBT_PRIVATE xbt_dict_t simcall_HANDLER_asr_get_properties(smx_simcall_t simcall, const char* name);
XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max);
\ No newline at end of file
return simcall<xbt_dict_t, smx_storage_t>(SIMCALL_STORAGE_GET_CONTENT, storage);
}
-inline static xbt_dict_t simcall_BODY_asr_get_properties(const char* name) {
- /* Go to that function to follow the code flow through the simcall barrier */
- if (0) simcall_HANDLER_asr_get_properties(&SIMIX_process_self()->simcall, name);
- return simcall<xbt_dict_t, const char*>(SIMCALL_ASR_GET_PROPERTIES, name);
- }
-
inline static int simcall_BODY_mc_random(int min, int max) {
/* Go to that function to follow the code flow through the simcall barrier */
if (0) simcall_HANDLER_mc_random(&SIMIX_process_self()->simcall, min, max);
SIMCALL_STORAGE_GET_USED_SIZE,
SIMCALL_STORAGE_GET_PROPERTIES,
SIMCALL_STORAGE_GET_CONTENT,
- SIMCALL_ASR_GET_PROPERTIES,
SIMCALL_MC_RANDOM,
SIMCALL_SET_CATEGORY,
SIMCALL_RUN_KERNEL,
"SIMCALL_STORAGE_GET_USED_SIZE",
"SIMCALL_STORAGE_GET_PROPERTIES",
"SIMCALL_STORAGE_GET_CONTENT",
- "SIMCALL_ASR_GET_PROPERTIES",
"SIMCALL_MC_RANDOM",
"SIMCALL_SET_CATEGORY",
"SIMCALL_RUN_KERNEL",
SIMIX_simcall_answer(simcall);
break;
-case SIMCALL_ASR_GET_PROPERTIES:
- simgrid::simix::marshal<xbt_dict_t>(simcall->result, simcall_HANDLER_asr_get_properties(simcall, simgrid::simix::unmarshal<const char*>(simcall->args[0])));
- SIMIX_simcall_answer(simcall);
- break;
-
case SIMCALL_MC_RANDOM:
simgrid::simix::marshal<int>(simcall->result, simcall_HANDLER_mc_random(simcall, simgrid::simix::unmarshal<int>(simcall->args[0]), simgrid::simix::unmarshal<int>(simcall->args[1])));
SIMIX_simcall_answer(simcall);
xbt_dict_t storage_get_properties(smx_storage_t storage) [[nohandler]];
xbt_dict_t storage_get_content(smx_storage_t storage) [[nohandler]];
-xbt_dict_t asr_get_properties(const char* name);
int mc_random(int min, int max);
void set_category(smx_activity_t synchro, const char* category) [[nohandler]];
}
}
-xbt_dict_t simcall_HANDLER_asr_get_properties(smx_simcall_t simcall, const char *name){
- return SIMIX_asr_get_properties(name);
-}
-xbt_dict_t SIMIX_asr_get_properties(const char *name)
-{
- return static_cast<xbt_dict_t>(xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL));
-}
-
int SIMIX_is_maestro()
{
return simix_global==nullptr /*SimDag*/|| SIMIX_process_self() == simix_global->maestro_process;
watched_hosts_lib = xbt_dict_new_homogeneous(nullptr);
XBT_DEBUG("Add routing levels");
- ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib, nullptr);
ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib, [](void* p) {
delete static_cast<simgrid::kernel::routing::NetCard*>(p);
});
xbt_lib_t as_router_lib;
int ROUTING_ASR_LEVEL = -1; //Routing level
-int ROUTING_PROP_ASR_LEVEL = -1; //Where the properties are stored
#include <stdarg.h> /* va_arg */
#include "simgrid/link.h"
+#include "simgrid/s4u/engine.hpp"
#include "simgrid/sg_config.h"
#include "src/kernel/routing/NetCard.hpp"
#include "src/surf/network_interface.hpp"
/* The default current property receiver. Setup in the corresponding opening callbacks. */
xbt_dict_t current_property_set = nullptr;
xbt_dict_t current_model_property_set = nullptr;
-xbt_dict_t as_current_property_set = nullptr;
-int AS_TAG = 0;
-char* as_name_tab[1024];
-void* as_dict_tab[1024];
-int as_prop_nb = 0;
-
+int AS_TAG = 0; // Whether we just opened an AS tag (to see what to do with the properties)
/* dictionary of random generator data */
xbt_dict_t random_data_list = nullptr;
void STag_surfxml_prop()
{
- if(AS_TAG){ // We need a stack here to retrieve the most recently opened AS
- if (!as_current_property_set){
- xbt_assert(as_prop_nb < 1024, "Number of AS property reach the limit!!!");
- as_current_property_set = xbt_dict_new_homogeneous(xbt_free_f); // Maybe, it should raise an error
- as_name_tab[as_prop_nb] = xbt_strdup(A_surfxml_AS_id);
- as_dict_tab[as_prop_nb] = as_current_property_set;
- XBT_DEBUG("PUSH prop set %p for AS '%s'",as_dict_tab[as_prop_nb],as_name_tab[as_prop_nb]);
- as_prop_nb++;
- }
- XBT_DEBUG("add prop %s=%s into current AS property set", A_surfxml_prop_id, A_surfxml_prop_value);
- xbt_dict_set(as_current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
+ if (AS_TAG) { // We need to retrieve the most recently opened AS
+ XBT_DEBUG("Set AS property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
+ simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_AS_id);
+
+ netzone->setProperty(A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value));
}
else{
if (!current_property_set)
current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
- XBT_DEBUG("add prop %s=%s into current property set", A_surfxml_prop_id, A_surfxml_prop_value);
+ XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
+ current_property_set);
}
}
void ETag_surfxml_cluster(){
s_sg_platf_cluster_cbarg_t cluster;
memset(&cluster,0,sizeof(cluster));
- cluster.properties = as_current_property_set;
+ cluster.properties = current_property_set;
cluster.id = A_surfxml_cluster_id;
cluster.prefix = A_surfxml_cluster_prefix;
}
void STag_surfxml_cluster(){
+ AS_TAG = 0;
parse_after_config();
xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
}
AS_TAG = 1;
s_sg_platf_AS_cbarg_t AS = { A_surfxml_AS_id, (int)A_surfxml_AS_routing};
- as_current_property_set = nullptr;
-
sg_platf_new_AS_begin(&AS);
}
void ETag_surfxml_AS(){
- if(as_prop_nb){
- char *name = as_name_tab[as_prop_nb-1];
- xbt_dict_t dict = (xbt_dict_t) as_dict_tab[as_prop_nb-1];
- as_prop_nb--;
- XBT_DEBUG("POP prop %p for AS '%s'",dict,name);
- xbt_lib_set(as_router_lib, name, ROUTING_PROP_ASR_LEVEL, dict);
- xbt_free(name);
- }
sg_platf_new_AS_seal();
}
}
int_f_void_t surf_parse = _surf_parse;
-
-/* Prop tag functions
- *
- * With XML parser
- */
-xbt_dict_t get_as_router_properties(const char* name)
-{
- return (xbt_dict_t)xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);
-}