From 74129886ba519295a41ea20004a4d5c07e06212b Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 13 Dec 2021 11:40:22 +0100 Subject: [PATCH] Add a function to retrieve the ns3 node from the s4u host --- include/simgrid/plugins/ns3.hpp | 20 ++++++++++++++++++++ src/surf/network_ns3.cpp | 12 ++++++++++-- tools/cmake/DefinePackages.cmake | 4 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 include/simgrid/plugins/ns3.hpp diff --git a/include/simgrid/plugins/ns3.hpp b/include/simgrid/plugins/ns3.hpp new file mode 100644 index 0000000000..06e4b395fe --- /dev/null +++ b/include/simgrid/plugins/ns3.hpp @@ -0,0 +1,20 @@ +/* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_PLUGINS_LOAD_H_ +#define SIMGRID_PLUGINS_LOAD_H_ + +#include +#include +#include +#include +#include + +namespace simgrid { +/** Returns the ns3 node from a simgrid host */ +XBT_PUBLIC ns3::Ptr get_ns3node_from_sghost(simgrid::s4u::Host* host); +}; // namespace simgrid + +#endif diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index fdb7e0ddf3..82e59a5aa3 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -3,6 +3,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/plugins/ns3.hpp" + #include #include @@ -517,8 +519,8 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s static uint16_t port_number = 1; - ns3::Ptr src_node = src->get_netpoint()->extension()->ns3_node_; - ns3::Ptr dst_node = dst->get_netpoint()->extension()->ns3_node_; + ns3::Ptr src_node = get_ns3node_from_sghost(src); + ns3::Ptr dst_node = get_ns3node_from_sghost(dst); std::string& addr = dst->get_netpoint()->extension()->ipv4_address_; xbt_assert(not addr.empty(), "Element %s is unknown to ns-3. Is it connected to any one-hop link?", @@ -564,6 +566,12 @@ void NetworkNS3Action::update_remains_lazy(double /*now*/) } // namespace resource } // namespace kernel + +ns3::Ptr get_ns3node_from_sghost(simgrid::s4u::Host* host) +{ + xbt_assert(host->get_netpoint()->extension() != nullptr, "Please only use this function on ns-3 nodes"); + return host->get_netpoint()->extension()->ns3_node_; +} } // namespace simgrid void ns3_simulator(double maxSeconds) diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ab7863b868..5562291885 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -833,7 +833,11 @@ if(SIMGRID_HAVE_MC) endif() if(SIMGRID_HAVE_NS3) + set(headers_to_install ${headers_to_install} include/simgrid/plugins/ns3.hpp) + set(simgrid_sources ${simgrid_sources} ${NS3_SRC}) +else() + set(EXTRA_DIST ${EXTRA_DIST} include/simgrid/plugins/ns3.hpp) endif() if(SIMGRID_HAVE_LUA) -- 2.20.1