A Discrete-Event Network Simulator
API
rng-seed-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Mathieu Lacage
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #include "rng-seed-manager.h"
21 #include "global-value.h"
22 #include "attribute-helper.h"
23 #include "integer.h"
24 #include "config.h"
25 #include "log.h"
26 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("RngSeedManager");
36 
42 static uint64_t g_nextStreamIndex = 0;
52 static ns3::GlobalValue g_rngSeed ("RngSeed",
53  "The global seed of all rng streams",
55  ns3::MakeIntegerChecker<uint32_t> ());
65 static ns3::GlobalValue g_rngRun ("RngRun",
66  "The substream index used for all streams",
68  ns3::MakeIntegerChecker<int64_t> ());
69 
70 
71 uint32_t RngSeedManager::GetSeed (void)
72 {
74  IntegerValue seedValue;
75  g_rngSeed.GetValue (seedValue);
76  return seedValue.Get ();
77 }
78 void
79 RngSeedManager::SetSeed (uint32_t seed)
80 {
81  NS_LOG_FUNCTION (seed);
82  Config::SetGlobal ("RngSeed", IntegerValue(seed));
83 }
84 
85 void RngSeedManager::SetRun (uint64_t run)
86 {
87  NS_LOG_FUNCTION (run);
88  Config::SetGlobal ("RngRun", IntegerValue (run));
89 }
90 
92 {
94  IntegerValue value;
95  g_rngRun.GetValue (value);
96  int run = value.Get();
97  return run;
98 }
99 
101 {
103  uint64_t next = g_nextStreamIndex;
104  g_nextStreamIndex++;
105  return next;
106 }
107 
108 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a signed integer type.
Definition: integer.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Hold a so-called 'global value'.
Definition: global-value.h:73
Declaration of the various ns3::Config functions and classes.
static void SetRun(uint64_t run)
Set the run number of simulation.
static uint64_t GetRun(void)
Get the current run number.
int64_t Get(void) const
Definition: integer.cc:35
ns3::RngSeedManager declaration.
static ns3::GlobalValue g_rngSeed("RngSeed","The global seed of all rng streams", ns3::IntegerValue(1), ns3::MakeIntegerChecker< uint32_t >())
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::GlobalValue declaration.
static uint32_t GetSeed(void)
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
Attribute helper (ATTRIBUTE_ )macros definition.
static void SetSeed(uint32_t seed)
Set the seed.
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:822
ns3::IntegerValue attribute value declarations and template implementations.
static ns3::GlobalValue g_rngRun("RngRun","The substream index used for all streams", ns3::IntegerValue(1), ns3::MakeIntegerChecker< int64_t >())
static uint64_t GetNextStreamIndex(void)
Get the next automatically assigned stream index.
static uint64_t g_nextStreamIndex
Debug message logging.
void GetValue(AttributeValue &value) const
Get the value.