typedef xbt_dictelm_t sg_host_t;
XBT_PUBLIC(sg_host_t) sg_host_by_name(const char *name);
+XBT_PUBLIC(sg_host_t) sg_host_by_name_or_create(const char *name);
static XBT_INLINE char *sg_host_get_name(sg_host_t host){
return host->key;
}
XBT_PUBLIC(void) sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu);
XBT_PUBLIC(void) sg_host_surfcpu_destroy(sg_host_t host);
+// ========== RoutingEdge ============
+typedef struct RoutingEdge *RoutingEdgePtr;
+XBT_PUBLIC(RoutingEdgePtr) sg_host_edge(sg_host_t host);
+XBT_PUBLIC(void) sg_host_edge_set(sg_host_t host, RoutingEdgePtr edge);
+XBT_PUBLIC(void) sg_host_edge_destroy(sg_host_t host, int do_callback);
+
// Module initializer. Won't survive the conversion to C++. Hopefully.
XBT_PUBLIC(void) sg_host_init(void);
SG_BEGIN_DECL()
XBT_PUBLIC_DATA(xbt_lib_t) host_lib;
-XBT_PUBLIC_DATA(int) ROUTING_HOST_LEVEL; //Routing level
XBT_PUBLIC_DATA(int) SURF_HOST_LEVEL; //Surf workstation level
XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
XBT_PUBLIC_DATA(int) SD_HOST_LEVEL; //Simdag host level
}
NetworkLinkDynar getRoute(char *srcName, char *dstName) {
- RoutingEdge *src = (RoutingEdge*)xbt_lib_get_or_null(host_lib, srcName, ROUTING_HOST_LEVEL);
- RoutingEdge *dst = (RoutingEdge*)xbt_lib_get_or_null(host_lib, dstName, ROUTING_HOST_LEVEL);
+ RoutingEdge *src = sg_host_edge(sg_host_by_name(srcName));
+ RoutingEdge *dst = sg_host_edge(sg_host_by_name(dstName));
xbt_assert(src,"Cannot get the route from a NULL source");
xbt_assert(dst,"Cannot get the route to a NULL destination");
xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL);
static inline surf_host_t surf_host_resource_priv(const void *host){
return (surf_host_t) xbt_lib_get_level((xbt_dictelm_t)host, SURF_HOST_LEVEL);
}
-static inline void *surf_routing_resource_priv(const void *host){
- return (void*)xbt_lib_get_level((xbt_dictelm_t)host, ROUTING_HOST_LEVEL);
-}
static inline void *surf_storage_resource_priv(const void *storage){
return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL);
}
new->name = xbt_strdup (name); // name of the container
new->id = xbt_strdup (id_str); // id (or alias) of the container
new->father = father;
+ sg_host_t sg_host = sg_host_by_name(name);
//Search for network_element_t
switch (kind){
case INSTR_HOST:
- new->net_elm = xbt_lib_get_or_null(host_lib,name,ROUTING_HOST_LEVEL);
+ new->net_elm = sg_host_edge(sg_host);
if(!new->net_elm) xbt_die("Element '%s' not found",name);
break;
case INSTR_ROUTER:
return xbt_lib_get_elm_or_null(host_lib, name);
}
+sg_host_t sg_host_by_name_or_create(const char *name) {
+ sg_host_t res = xbt_lib_get_elm_or_null(host_lib, name);
+ if (!res) {
+ xbt_lib_set(host_lib,name,0,NULL); // Should only create the bucklet with no data added
+ res = xbt_lib_get_elm_or_null(host_lib, name);
+ }
+ return res;
+}
+
// ========= Layering madness ==============
-int SIMIX_HOST_LEVEL;
int MSG_HOST_LEVEL;
+int SIMIX_HOST_LEVEL;
+int ROUTING_HOST_LEVEL;
int SURF_CPU_LEVEL;
+
#include "simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme
#include "msg/msg_private.h" // MSG_host_priv_free. FIXME: killme
#include "surf/cpu_interface.hpp"
+#include "surf/surf_routing.hpp"
static XBT_INLINE void surf_cpu_free(void *r) {
delete static_cast<CpuPtr>(r);
}
+static XBT_INLINE void routing_asr_host_free(void *p) {
+ delete static_cast<RoutingEdgePtr>(p);
+}
void sg_host_init() {
SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free);
SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free);
+ ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
}
-
// ========== MSG Layer ==============
msg_host_priv_t sg_host_msg(sg_host_t host) {
return (msg_host_priv_t) xbt_lib_get_level(host, MSG_HOST_LEVEL);
void sg_host_surfcpu_destroy(sg_host_t host) {
xbt_lib_unset(host_lib,host->key,SURF_CPU_LEVEL,1);
}
+// ========== RoutingEdge ============
+RoutingEdgePtr sg_host_edge(sg_host_t host) {
+ return (RoutingEdgePtr) xbt_lib_get_level(host, ROUTING_HOST_LEVEL);
+}
+void sg_host_edge_set(sg_host_t host, RoutingEdgePtr edge) {
+ xbt_lib_set(host_lib, host->key, ROUTING_HOST_LEVEL, edge);
+}
+void sg_host_edge_destroy(sg_host_t host, int do_callback) {
+ xbt_lib_unset(host_lib,host->key,ROUTING_HOST_LEVEL,do_callback);
+}
sg_host_t sg_host = sg_host_by_name(name);
HostPtr host = new HostCLM03(surf_host_model, name, NULL,
(xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
- (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL),
+ sg_host_edge(sg_host),
sg_host_surfcpu(sg_host));
XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage));
xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host);
name);
wk = new HostL07(this, name, NULL,
- static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL)),
+ sg_host_edge(sg_host),
sg_host_surfcpu(sg_host));
xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, wk);
return static_cast<HostPtr>(surf_host_resource_priv(resource));
}
-static RoutingEdgePtr get_casted_routing(surf_resource_t resource){
- return static_cast<RoutingEdgePtr>(surf_routing_resource_priv(resource));
-}
-
static VMPtr get_casted_vm(surf_resource_t resource){
return static_cast<VMPtr>(surf_host_resource_priv(resource));
}
void surf_vm_destroy(surf_resource_t resource){
/* Before clearing the entries in host_lib, we have to pick up resources. */
VMPtr vm = get_casted_vm(resource);
- RoutingEdgePtr routing = get_casted_routing(resource);
char* name = xbt_dict_get_elm_key(resource);
/* We deregister objects from host_lib, without invoking the freeing callback
* of each level.
* including MSG_HOST_LEVEL and others. We should unregister only what we know.
*/
sg_host_surfcpu_destroy((sg_host_t)resource);
- xbt_lib_unset(host_lib, name, ROUTING_HOST_LEVEL, 0);
+ sg_host_edge_destroy((sg_host_t)resource,1);
xbt_lib_unset(host_lib, name, SURF_HOST_LEVEL, 0);
/* TODO: comment out when VM storage is implemented. */
// xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
delete vm;
- delete routing;
}
void surf_vm_suspend(surf_resource_t vm){
return -1;
}
-static XBT_INLINE void routing_asr_host_free(void *p)
-{
- delete ((RoutingEdgePtr) p);
-}
-
static XBT_INLINE void routing_asr_prop_free(void *p)
{
- xbt_dict_t elm = (xbt_dict_t) p;
- xbt_dict_free(&elm);
+ //xbt_dict_t elm = (xbt_dict_t) p;
+ //xbt_dict_free(&elm); FIXME: leaking in some case? That's a sometimes double-free with AsCluster::~AsCluster
}
static XBT_INLINE void surf_link_free(void *r)
sg_host_init();
XBT_DEBUG("Add routing levels");
- ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
- ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free);
ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
XBT_DEBUG("Add SURF levels");
*/
xbt_lib_t host_lib;
-int ROUTING_HOST_LEVEL; //Routing level
int SURF_HOST_LEVEL; //Surf host level
int SIMIX_STORAGE_LEVEL; //Simix storage level
int MSG_STORAGE_LEVEL; //Msg storage level
* Routing edges are either host and routers, whatever
*/
RoutingEdgePtr sg_routing_edge_by_name_or_null(const char *name) {
- RoutingEdgePtr net_elm = (RoutingEdgePtr) xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
+ sg_host_t h = sg_host_by_name(name);
+ RoutingEdgePtr net_elm = h==NULL?NULL: sg_host_edge(h);
if (!net_elm)
net_elm = (RoutingEdgePtr) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
return net_elm;
*/
static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
{
- RoutingEdgePtr info = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL));
+ RoutingEdgePtr info = sg_host_edge(sg_host_by_name(host->id));
xbt_assert(info, "Host '%s' not found!", host->id);
xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] ||
current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI],
{
if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
current_routing->p_hierarchy = SURF_ROUTING_BASE;
- xbt_assert(!xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL),
- "Reading a host, processing unit \"%s\" already exists", host->id);
+ xbt_assert(!sg_host_by_name(host->id),
+ "Reading a host, processing unit \"%s\" already exists", host->id);
RoutingEdgePtr info = new RoutingEdgeImpl(xbt_strdup(host->id),
-1,
SURF_NETWORK_ELEMENT_HOST,
current_routing);
info->setId(current_routing->parsePU(info));
- xbt_lib_set(host_lib, host->id, ROUTING_HOST_LEVEL, (void *) info);
+ sg_host_edge_set(sg_host_by_name_or_create(host->id), info);
XBT_DEBUG("Having set name '%s' id '%d'", host->id, info->getId());
if(mount_list){
* Classes *
***********/
-/* Note: As and RoutingEdge are declard as struct instead of class, to keep
+/* Note: As and RoutingEdge are declared as struct instead of class, to keep
compatibility with C files where they are mentioned. */
struct As;
typedef As *AsPtr;
class RoutingModelDescription;
typedef RoutingModelDescription *RoutingModelDescriptionPtr;
-struct RoutingEdge;
-typedef RoutingEdge *RoutingEdgePtr;
-
class Onelink;
typedef Onelink *OnelinkPtr;
AsPtr AsGeneric::processingUnitsExist(char *element)
{
- AsPtr element_as;
- element_as = ((RoutingEdgePtr)
- xbt_lib_get_or_null(host_lib,
- element, ROUTING_HOST_LEVEL))->getRcComponent();
+ AsPtr element_as = sg_host_edge(sg_host_by_name(element)) ->getRcComponent();
if (element_as == this)
return element_as;
return asExist(element_as);
* from the VM name, we have to make sure that the system does not call the
* free callback for the network resource object. The network resource object
* is still used by the physical machine. */
- p_netElm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL)));
- xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, p_netElm);
+ sg_host_t sg_sub_ws = sg_host_by_name_or_create(sub_ws->getName());
+ p_netElm = new RoutingEdgeWrapper(sg_host_edge(sg_sub_ws));
+ sg_host_edge_set(sg_host_by_name_or_create(name), p_netElm);
p_subWs = sub_ws;
p_currentState = SURF_VM_STATE_CREATED;
xbt_assert(ws_dst);
- /* do something */
-
/* update net_elm with that of the destination physical host */
RoutingEdgePtr old_net_elm = p_netElm;
- RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, pm_name_dst, ROUTING_HOST_LEVEL)));
+ RoutingEdgePtr new_net_elm = new RoutingEdgeWrapper(sg_host_edge(sg_host_by_name(pm_name_dst)));
xbt_assert(new_net_elm);
/* Unregister the current net_elm from host_lib. Do not call the free callback. */
- xbt_lib_unset(host_lib, vm_name, ROUTING_HOST_LEVEL, 0);
+ sg_host_edge_destroy(sg_host_by_name(vm_name), 0);
/* Then, resister the new one. */
p_netElm = new_net_elm;
- xbt_lib_set(host_lib, vm_name, ROUTING_HOST_LEVEL, p_netElm);
+ sg_host_edge_set(sg_host_by_name(vm_name), p_netElm);
p_subWs = ws_dst;
elts[level] = obj;
}
-/* for vm */
void xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callback)
{
void **elts = xbt_dict_get_or_null(lib->dict, key);
xbt_lib_foreach(host_lib, cursor_src, src, value1) // Routes from host
{
- value1 = xbt_lib_get_or_null(host_lib,src,ROUTING_HOST_LEVEL);
+ value1 = sg_host_edge(sg_host_by_name(src));
xbt_lib_foreach(host_lib, cursor_dst, dst, value2) //to host
{
printf(" <route src=\"%s\" dst=\"%s\">\n "
,src
,dst);
xbt_dynar_t route=NULL;
- value2 = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL);
+ value2 = sg_host_edge(sg_host_by_name(dst));
routing_get_route_and_latency(value1,value2,&route,NULL);
for(i=0;i<xbt_dynar_length(route) ;i++)
{
printf(" <route src=\"%s\" dst=\"%s\">\n "
,src, dst);
xbt_dynar_t route=NULL;
- value2 = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL);
+ value2 = sg_host_edge(sg_host_by_name(dst));
routing_get_route_and_latency((sg_routing_edge_t)value1,(sg_routing_edge_t)value2,&route, NULL);
for(i=0;i<xbt_dynar_length(route) ;i++)
{