From bba1a9227833474247b4fca08cf607d611966133 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 8 Oct 2020 22:42:47 +0200 Subject: [PATCH 1/1] new option ns3/seed to seed the ns-3 random generator --- docs/source/Configuring_SimGrid.rst | 10 ++++++++++ src/surf/network_ns3.cpp | 20 +++++++++++++++++++- src/surf/network_ns3.hpp | 4 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/source/Configuring_SimGrid.rst b/docs/source/Configuring_SimGrid.rst index e7a968578b..f680b51178 100644 --- a/docs/source/Configuring_SimGrid.rst +++ b/docs/source/Configuring_SimGrid.rst @@ -132,6 +132,7 @@ Existing Configuration Items - **network/weight-S:** :ref:`cfg=network/weight-S` - **ns3/TcpModel:** :ref:`options_pls` +- **ns3/seed:** :ref:`options_pls` - **path:** :ref:`cfg=path` - **plugin:** :ref:`cfg=plugin` @@ -439,6 +440,15 @@ ns-3. The only valid values (enforced on the SimGrid side) are 'default' (no change to the ns-3 configuration), 'NewReno' or 'Reno' or 'Tahoe'. +**Option** ``ns3/seed`` **Default:** "" (don't set the seed in ns-3) + +This option is the random seed to provide to ns-3 with +``ns3::RngSeedManager::SetSeed`` and ``ns3::RngSeedManager::SetRun``. + +If left blank, no seed is set in ns-3. If the value 'time' is +provided, the current amount of seconds since epoch is used as a seed. +Otherwise, the provided value must be a number to use as a seed. + Configuring the Storage model ............................. diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index b44c56a99e..ace2e772fc 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -7,6 +7,7 @@ #include #include "xbt/config.hpp" +#include "xbt/str.h" #include "xbt/string.hpp" #include "xbt/utility.hpp" @@ -210,7 +211,24 @@ void surf_network_model_init_NS3() } static simgrid::config::Flag - ns3_tcp_model("ns3/TcpModel", "The ns-3 tcp model can be : NewReno or Reno or Tahoe", "default"); + ns3_tcp_model("ns3/TcpModel", "The ns-3 tcp model can be: NewReno or Reno or Tahoe", "default"); +static simgrid::config::Flag ns3_seed( + "ns3/seed", + "The random seed provided to ns-3. Either 'time' to seed with time(), blank to not set (default), or a number.", "", + [](std::string val) { + if (val.length() == 0) + return; + if (strcasecmp(val.c_str(), "time") == 0) { + std::srand(time(NULL)); + ns3::RngSeedManager::SetSeed(std::rand()); + ns3::RngSeedManager::SetRun(std::rand()); + } else { + int v = xbt_str_parse_int( + val.c_str(), "Invalid value for option ns3/seed. It must be either 'time', a number, or left empty."); + ns3::RngSeedManager::SetSeed(v); + ns3::RngSeedManager::SetRun(v); + } + }); namespace simgrid { namespace kernel { diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp index 6e6359573f..70a4586c8d 100644 --- a/src/surf/network_ns3.hpp +++ b/src/surf/network_ns3.hpp @@ -37,8 +37,8 @@ public: s4u::Link::SharingPolicy sharing_policy_; void apply_event(profile::Event* event, double value) override; - void set_bandwidth(double value) override { THROW_UNIMPLEMENTED; } - void set_latency(double value) override { THROW_UNIMPLEMENTED; } + void set_bandwidth(double) override { THROW_UNIMPLEMENTED; } + void set_latency(double) override { THROW_UNIMPLEMENTED; } void set_bandwidth_profile(profile::Profile* profile) override; void set_latency_profile(profile::Profile* profile) override; s4u::Link::SharingPolicy get_sharing_policy() override {return sharing_policy_;} -- 2.20.1