Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a function to retrieve the ns3 node from the s4u host
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 13 Dec 2021 10:40:22 +0000 (11:40 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 13 Dec 2021 10:40:22 +0000 (11:40 +0100)
include/simgrid/plugins/ns3.hpp [new file with mode: 0644]
src/surf/network_ns3.cpp
tools/cmake/DefinePackages.cmake

diff --git a/include/simgrid/plugins/ns3.hpp b/include/simgrid/plugins/ns3.hpp
new file mode 100644 (file)
index 0000000..06e4b39
--- /dev/null
@@ -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 <ns3/node.h>
+#include <ns3/ptr.h>
+#include <simgrid/config.h>
+#include <simgrid/forward.h>
+#include <xbt/base.h>
+
+namespace simgrid {
+/** Returns the ns3 node from a simgrid host */
+XBT_PUBLIC ns3::Ptr<ns3::Node> get_ns3node_from_sghost(simgrid::s4u::Host* host);
+}; // namespace simgrid
+
+#endif
index fdb7e0d..82e59a5 100644 (file)
@@ -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 <string>
 #include <unordered_set>
 
@@ -517,8 +519,8 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s
 
   static uint16_t port_number = 1;
 
-  ns3::Ptr<ns3::Node> src_node = src->get_netpoint()->extension<NetPointNs3>()->ns3_node_;
-  ns3::Ptr<ns3::Node> dst_node = dst->get_netpoint()->extension<NetPointNs3>()->ns3_node_;
+  ns3::Ptr<ns3::Node> src_node = get_ns3node_from_sghost(src);
+  ns3::Ptr<ns3::Node> dst_node = get_ns3node_from_sghost(dst);
 
   std::string& addr = dst->get_netpoint()->extension<NetPointNs3>()->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<ns3::Node> get_ns3node_from_sghost(simgrid::s4u::Host* host)
+{
+  xbt_assert(host->get_netpoint()->extension<NetPointNs3>() != nullptr, "Please only use this function on ns-3 nodes");
+  return host->get_netpoint()->extension<NetPointNs3>()->ns3_node_;
+}
 } // namespace simgrid
 
 void ns3_simulator(double maxSeconds)
index ab7863b..5562291 100644 (file)
@@ -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)