From: Martin Quinson Date: Thu, 8 Dec 2016 08:44:47 +0000 (+0100) Subject: make an As::onRouteCreation signal so that NS3 does not need getOneLinkRoutes afterward X-Git-Tag: v3_14~97 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/390ee57ed79bf7577c2bce6df6a25aba57ff476e make an As::onRouteCreation signal so that NS3 does not need getOneLinkRoutes afterward --- diff --git a/include/simgrid/s4u/As.hpp b/include/simgrid/s4u/As.hpp index 0a8c77a35a..21e57c6e5d 100644 --- a/include/simgrid/s4u/As.hpp +++ b/include/simgrid/s4u/As.hpp @@ -58,6 +58,12 @@ public: virtual void addRoute(sg_platf_route_cbarg_t route); void addBypassRoute(sg_platf_route_cbarg_t e_route); + /*** Called on each newly created regular route (not on bypass routes) */ + static simgrid::xbt::signal* link_list)> + onRouteCreation; + protected: std::vector vertices_; // our content, as known to our graph routing algorithm (maps vertexId -> vertex) diff --git a/src/kernel/routing/AsRoutedGraph.cpp b/src/kernel/routing/AsRoutedGraph.cpp index e0c289d346..aceae1afcf 100644 --- a/src/kernel/routing/AsRoutedGraph.cpp +++ b/src/kernel/routing/AsRoutedGraph.cpp @@ -230,6 +230,8 @@ void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) { xbt_assert(!route->link_list->empty(), "Empty route (between %s@%s and %s@%s) forbidden.", srcName, route->gw_src->cname(), dstName, route->gw_dst->cname()); } + + onRouteCreation(route->symmetrical, route->src, route->dst, route->gw_src, route->gw_dst, route->link_list); } }}} diff --git a/src/s4u/s4u_as.cpp b/src/s4u/s4u_as.cpp index 435572c084..ac3a1f5edd 100644 --- a/src/s4u/s4u_as.cpp +++ b/src/s4u/s4u_as.cpp @@ -18,6 +18,11 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_as,"S4U autonomous systems"); namespace simgrid { namespace s4u { + simgrid::xbt::signal* link_list)> + As::onRouteCreation; + As::As(As* father, const char* name) : father_(father), name_(xbt_strdup(name)) { } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index f0ec983771..5797b32474 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -101,53 +101,53 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) xbt_free(bw); } +static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetCard* src, + simgrid::kernel::routing::NetCard* dst, simgrid::kernel::routing::NetCard* gw_src, + simgrid::kernel::routing::NetCard* gw_dst, std::vector* link_list) +{ + if (link_list->size() == 1) { + simgrid::surf::LinkNS3* link = static_cast(link_list->at(0)); + + XBT_DEBUG("Route from '%s' to '%s' with link '%s' %s", src->cname(), dst->cname(), link->getName(), + (symmetrical ? "(symmetrical)" : "(not symmetrical)")); + char* link_bdw = bprintf("%fBps", link->bandwidth()); + char* link_lat = bprintf("%fs", link->latency()); + + // XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id); + XBT_DEBUG("\tLink (%s) bdw:%s lat:%s", link->getName(), link_bdw, link_lat); + + // create link ns3 + HostNs3* host_src = nullptr; + HostNs3* host_dst = nullptr; + if (src->isHost()) + host_src = sg_host_by_name(src->cname())->extension(); + else + host_src = static_cast(xbt_lib_get_or_null(as_router_lib, src->cname(), NS3_ASR_LEVEL)); + + if (dst->isHost()) + host_dst = sg_host_by_name(dst->cname())->extension(); + else + host_dst = static_cast(xbt_lib_get_or_null(as_router_lib, dst->cname(), NS3_ASR_LEVEL)); + + xbt_assert(host_src != nullptr, "Network element %s does not seem to be NS3-ready", src->cname()); + xbt_assert(host_dst != nullptr, "Network element %s does not seem to be NS3-ready", dst->cname()); + + ns3_add_link(host_src->node_num, host_dst->node_num, link_bdw, link_lat); + if (symmetrical) + ns3_add_link(host_dst->node_num, host_src->node_num, link_bdw, link_lat); + + xbt_free(link_bdw); + xbt_free(link_lat); + } +} + /* Create the ns3 topology based on routing strategy */ -static void create_ns3_topology(void) +static void postparse_cb(void) { XBT_DEBUG("Starting topology generation"); xbt_dynar_shrink(IPV4addr,0); - //get the onelinks from the parsed platform - std::vector onelink_routes; - static_cast(simgrid::s4u::Engine::instance()->rootAs()) - ->getOneLinkRoutes(&onelink_routes); - - std::unordered_set already_seen = std::unordered_set(); - - XBT_DEBUG("There is %ld one-link routes", onelink_routes.size()); - for (simgrid::kernel::routing::Onelink* onelink : onelink_routes) { - const char* src = onelink->src_->name().c_str(); - const char* dst = onelink->dst_->name().c_str(); - simgrid::surf::LinkNS3 *link = static_cast(onelink->link_); - - if (strcmp(src,dst) && (already_seen.find(link) == already_seen.end())) { - already_seen.insert(link); - XBT_DEBUG("Route from '%s' to '%s' with link '%s'", src, dst, link->getName()); - char* link_bdw = bprintf("%fBps", link->bandwidth()); - char* link_lat = bprintf("%fs", link->latency()); - - // XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id); - XBT_DEBUG("\tLink (%s) bdw:%s lat:%s", link->getName(), link_bdw, link_lat); - - //create link ns3 - HostNs3* host_src = ns3_find_host(src); - if (!host_src) - host_src = static_cast(xbt_lib_get_or_null(as_router_lib, src, NS3_ASR_LEVEL)); - HostNs3* host_dst = ns3_find_host(dst); - if(!host_dst) - host_dst = static_cast(xbt_lib_get_or_null(as_router_lib, dst, NS3_ASR_LEVEL)); - - if (!host_src || !host_dst) - xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num); - - ns3_add_link(host_src->node_num, host_dst->node_num, link_bdw, link_lat); - - xbt_free(link_bdw); - xbt_free(link_lat); - } - } - ns3::GlobalRouteManager::BuildGlobalRoutingDatabase(); ns3::GlobalRouteManager::InitializeRoutes(); } @@ -179,7 +179,8 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel() { simgrid::s4u::Host::onCreation.connect(ns3_add_host); simgrid::kernel::routing::netcardCreatedCallbacks.connect(ns3_add_netcard); simgrid::surf::on_cluster.connect (&parse_ns3_add_cluster); - simgrid::surf::on_postparse.connect(&create_ns3_topology); + simgrid::surf::on_postparse.connect(&postparse_cb); + simgrid::s4u::As::onRouteCreation.connect(&routeCreation_cb); HostNs3::EXTENSION_ID = simgrid::s4u::Host::extension_create(); @@ -315,11 +316,11 @@ void LinkNS3::setLatencyTrace(tmgr_trace_t trace) { NetworkNS3Action::NetworkNS3Action(Model* model, double size, s4u::Host* src, s4u::Host* dst) : NetworkAction(model, size, false) { - XBT_DEBUG("Communicate from %s to %s", src->name().c_str(), dst->name().c_str()); + XBT_DEBUG("Communicate from %s to %s", src->cname(), dst->cname()); src_ = src; dst_ = dst; - ns3_create_flow(src->name().c_str(), dst->name().c_str(), surf_get_clock(), size, this); + ns3_create_flow(src, dst, surf_get_clock(), size, this); Link::onCommunicate(this, src, dst); } @@ -354,17 +355,19 @@ int NetworkNS3Action::unref() } } -void ns3_simulator(double maxSeconds){ +void ns3_simulator(double maxSeconds) +{ if (maxSeconds > 0.0) // If there is a maximum amount of time to run ns3::Simulator::Stop(ns3::Seconds(maxSeconds)); - XBT_DEBUG("Start simulator for at most %fs",maxSeconds); + XBT_DEBUG("Start simulator for at most %fs (current time: %f)", maxSeconds, surf_get_clock()); ns3::Simulator::Run (); } -void ns3_create_flow(const char* a,const char *b,double startTime,u_int32_t TotalBytes,simgrid::surf::NetworkNS3Action * action) +void ns3_create_flow(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double startTime, u_int32_t TotalBytes, + simgrid::surf::NetworkNS3Action* action) { - int node1 = ns3_find_host(a)->node_num; - int node2 = ns3_find_host(b)->node_num; + int node1 = src->extension()->node_num; + int node2 = dst->extension()->node_num; ns3::Ptr src_node = nodes.Get(node1); ns3::Ptr dst_node = nodes.Get(node2); diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index 187deb594d..11f48710b5 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -32,7 +32,9 @@ public: SG_BEGIN_DECL() XBT_PUBLIC(void) ns3_initialize(const char* TcpProtocol); -XBT_PUBLIC(void) ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalBytes,simgrid::surf::NetworkNS3Action * action); +XBT_PUBLIC(void) +ns3_create_flow(sg_host_t src, sg_host_t dst, double start, u_int32_t TotalBytes, + simgrid::surf::NetworkNS3Action* action); XBT_PUBLIC(void) ns3_simulator(double maxSeconds); XBT_PUBLIC(void *) ns3_add_router(const char * id); XBT_PUBLIC(void) ns3_add_link(int src, int dst, char * bw,char * lat);