A Discrete-Event Network Simulator
API
sample-log-time-format.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
87 #include "ns3/simulator.h"
88 #include "ns3/nstime.h"
89 #include "ns3/command-line.h"
90 #include "ns3/log.h"
91 #include "ns3/random-variable-stream.h"
92 
93 using namespace ns3;
94 
95 namespace {
96 
105 void
106 ReplacementTimePrinter (std::ostream &os)
107 {
108  os << Simulator::Now ().GetSeconds () << "s";
109 }
110 
112 void
114 {
115  std::cout << "Replacing time printer function after Simulator::Run ()" << std::endl;
117 }
118 
119 
120 } // unnamed namespace
121 
122 
123 int main (int argc, char *argv[])
124 {
125  bool replaceTimePrinter = false;
126  std::string resolution = "Time::NS";
127  LogComponentEnable ("RandomVariableStream", LOG_LEVEL_ALL);
129 
130  std::map<std::string, Time::Unit> resolutionMap = {{"Time::US", Time::US}, {"Time::NS", Time::NS}, {"Time::PS", Time::PS}, {"Time::FS", Time::FS}};
131 
133  cmd.AddValue ("replaceTimePrinter", "replace time printing function", replaceTimePrinter);
134  cmd.AddValue ("resolution", "time resolution", resolution);
135  cmd.Parse (argc, argv);
136 
137  auto search = resolutionMap.find (resolution);
138  if (search != resolutionMap.end ())
139  {
140  Time::SetResolution (search->second);
141  }
142 
143  Ptr<UniformRandomVariable> uniformRv = CreateObject<UniformRandomVariable> ();
144 
145  if (replaceTimePrinter)
146  {
148  }
149 
153  Simulator::Schedule (NanoSeconds (123456789), &UniformRandomVariable::SetAntithetic, uniformRv, false);
154 
155  Simulator::Run ();
157 }
void SetAntithetic(bool isAntithetic)
Specify whether antithetic values should be generated.
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
tuple cmd
Definition: second.py:35
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:369
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1375
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1017
femtosecond
Definition: nstime.h:119
Parse command-line arguments.
Definition: command-line.h:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
void ReplacementTimePrinter(std::ostream &os)
Pre-ns-3.26 LogTimePrinter equivalent.
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
Definition: log.cc:393
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Prefix all trace prints with simulation time.
Definition: log.h:115
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void ReplaceTimePrinter(void)
Set ReplacementTimePrinter as the time printer for log messages.
void LogSetTimePrinter(LogTimePrinter printer)
Set the LogTimePrinter function to be used to prepend log messages with the simulation time...
Definition: log.cc:629
microsecond
Definition: nstime.h:116
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
static void SetResolution(enum Unit resolution)
Definition: time.cc:180
Print everything.
Definition: log.h:112
void Parse(int argc, char *argv[])
Parse the program arguments.
picosecond
Definition: nstime.h:118
nanosecond
Definition: nstime.h:117