From: Martin Quinson Date: Thu, 24 Dec 2015 14:19:09 +0000 (+0100) Subject: port NS3 to the new extension mechanism X-Git-Tag: v3_13~1393 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/084e76d536977bc9b57d9e7c01aa9feb41551fd0 port NS3 to the new extension mechanism --- diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index da85c7281f..5b713baf19 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -17,7 +17,6 @@ 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_STORAGE_LEVEL; //Simdag storage level XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL; //Coordinates level -XBT_PUBLIC_DATA(int) NS3_HOST_LEVEL; //host node for ns3 XBT_PUBLIC_DATA(xbt_lib_t) as_router_lib; XBT_PUBLIC_DATA(int) ROUTING_ASR_LEVEL; //Routing level diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 709b10502c..5e38359996 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -11,6 +11,8 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3); +int NS3_EXTENSION_ID; + xbt_dynar_t IPV4addr; static double time_to_next_flow_completion = -1; @@ -41,7 +43,7 @@ static void simgrid_ns3_add_host(simgrid::surf::Host* host) { const char* id = host->getName(); XBT_DEBUG("NS3_ADD_HOST '%s'", id); - host->getHost()->set_facet(NS3_HOST_LEVEL, ns3_add_host(id)); + host->getHost()->extension_set(NS3_EXTENSION_ID, ns3_add_host(id)); } static void parse_ns3_add_link(sg_platf_link_cbarg_t link) @@ -109,7 +111,7 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) xbt_dynar_push_as(tab_elements_num, int, start); router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix); simgrid::Host::by_name_or_create(router_id) - ->set_facet(NS3_HOST_LEVEL, ns3_add_host_cluster(router_id)); + ->extension_set(NS3_EXTENSION_ID, ns3_add_host_cluster(router_id)); XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id); free(router_id); break; @@ -121,7 +123,7 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) xbt_dynar_push_as(tab_elements_num, int, i); router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix); simgrid::Host::by_name_or_create(router_id) - ->set_facet(NS3_HOST_LEVEL, ns3_add_host_cluster(router_id)); + ->extension_set(NS3_EXTENSION_ID, ns3_add_host_cluster(router_id)); XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id); free(router_id); } @@ -228,7 +230,7 @@ static void parse_ns3_end_platform(void) static void define_callbacks_ns3(void) { - simgrid::surf::hostCreatedCallbacks.connect(simgrid_ns3_add_host); + simgrid::surf::Host::onCreation.connect(simgrid_ns3_add_host); simgrid::surf::routingEdgeCreatedCallbacks.connect(simgrid_ns3_add_router); sg_platf_link_add_cb (&parse_ns3_add_link); sg_platf_cluster_add_cb (&parse_ns3_add_cluster); @@ -271,7 +273,7 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel() { routing_model_create(NULL); define_callbacks_ns3(); - NS3_HOST_LEVEL = simgrid::Host::add_level(free_ns3_host); + NS3_EXTENSION_ID = simgrid::Host::extension_create(free_ns3_host); NS3_ASR_LEVEL = xbt_lib_add_level(as_router_lib, free_ns3_host); } @@ -297,7 +299,7 @@ Link* NetworkNS3Model::createLink(const char *name, if (state_trace) XBT_INFO("The NS3 network model doesn't support link state traces"); Link* link = new NetworkNS3Link(this, name, properties, bw_initial, lat_initial); - networkLinkCreatedCallbacks(link); + Link::onCreation(link); return link; } diff --git a/src/surf/ns3/ns3_interface.cc b/src/surf/ns3/ns3_interface.cc index bd9a5586f6..3b516ff07f 100644 --- a/src/surf/ns3/ns3_interface.cc +++ b/src/surf/ns3/ns3_interface.cc @@ -9,11 +9,11 @@ #include "xbt/lib.h" #include "xbt/log.h" #include "xbt/dynar.h" +#include "xbt/Extendable.hpp" using namespace ns3; -extern int NS3_HOST_LEVEL; //host node for ns3 extern xbt_dynar_t IPV4addr; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ns3, surf, diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index 36c8aa7c78..480947eb76 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -11,8 +11,9 @@ #include "xbt/dynar.h" #include "xbt/misc.h" #include "xbt/sysdep.h" +#include -#include +#include #include typedef enum { @@ -22,12 +23,15 @@ typedef enum { NS3_NETWORK_ELEMENT_AS, /* AS type */ } e_ns3_network_element_type_t; + typedef struct ns3_nodes{ int node_num; e_ns3_network_element_type_t type; void * data; }s_ns3_nodes_t, *ns3_nodes_t; +XBT_PUBLIC_DATA(int) NS3_EXTENSION_ID; + SG_BEGIN_DECL() XBT_PUBLIC(int) ns3_finalize(void); @@ -56,7 +60,7 @@ ns3_nodes_t ns3_find_host(const char* id) if (host == nullptr) return nullptr; else - return (ns3_nodes_t) sg_host_get_extension(host, NS3_HOST_LEVEL); + return (ns3_nodes_t) host->extension(NS3_EXTENSION_ID); } SG_END_DECL() diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index dbc30ef44d..8b2a02bded 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -37,7 +37,6 @@ xbt_dict_t host_list; int SURF_HOST_LEVEL; //Surf host level int COORD_HOST_LEVEL=0; //Coordinates level -int NS3_HOST_LEVEL; //host node for ns3 int MSG_FILE_LEVEL; //Msg file level