A Discrete-Event Network Simulator
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2008 University of Washington
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
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 */
22#include "simulator-impl.h"
24#include "scheduler.h"
25#include "synchronizer.h"
26#include "event-impl.h"
28#include "ptr.h"
29#include "assert.h"
30#include "log.h"
32#include <list>
33#include <mutex>
34#include <thread>
42namespace ns3 {
63 static TypeId GetTypeId (void);
69 {
85 };
92 // Inherited from SimulatorImpl
93 virtual void Destroy ();
94 virtual bool IsFinished (void) const;
95 virtual void Stop (void);
96 virtual void Stop (const Time &delay);
97 virtual EventId Schedule (const Time &delay, EventImpl *event);
98 virtual void ScheduleWithContext (uint32_t context, const Time &delay, EventImpl *event);
99 virtual EventId ScheduleNow (EventImpl *event);
100 virtual EventId ScheduleDestroy (EventImpl *event);
101 virtual void Remove (const EventId &ev);
102 virtual void Cancel (const EventId &ev);
103 virtual bool IsExpired (const EventId &ev) const;
104 virtual void Run (void);
105 virtual Time Now (void) const;
106 virtual Time GetDelayLeft (const EventId &id) const;
107 virtual Time GetMaximumSimulationTime (void) const;
108 virtual void SetScheduler (ObjectFactory schedulerFactory);
109 virtual uint32_t GetSystemId (void) const;
110 virtual uint32_t GetContext (void) const;
111 virtual uint64_t GetEventCount (void) const;
114 void ScheduleRealtimeWithContext (uint32_t context, const Time &delay, EventImpl *event);
121 void ScheduleRealtime (const Time &delay, EventImpl *event);
134 void ScheduleRealtimeNow (EventImpl *event);
139 Time RealtimeNow (void) const;
159 void SetHardLimit (Time limit);
166 Time GetHardLimit (void) const;
173 bool Running (void) const;
178 bool Realtime (void) const;
183 uint64_t NextTs (void) const;
185 void ProcessOneEvent (void);
187 virtual void DoDispose (void);
190 typedef std::list<EventId> DestroyEvents;
194 bool m_stop;
213 uint64_t m_currentTs;
217 uint64_t m_eventCount;
221 mutable std::mutex m_mutex;
233 std::thread::id m_main;
236} // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
An identifier for simulation events.
Definition: event-id.h:54
A simulation event.
Definition: event-impl.h:45
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Realtime version of SimulatorImpl.
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Scheduler > m_events
The event list.
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
DestroyEvents m_destroyEvents
Container for events to be run at destroy time.
virtual void DoDispose(void)
Destructor implementation.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
int m_unscheduledEvents
Unique id for the next event to be scheduled.
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
bool m_running
Is the simulator currently running.
uint32_t m_currentContext
The event list.
virtual void Cancel(const EventId &ev)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
virtual void Remove(const EventId &ev)
Remove an event from the event list.
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
std::mutex m_mutex
Mutex to control access to key state.
SynchronizationMode m_synchronizationMode
SynchronizationMode policy.
uint64_t NextTs(void) const
Get the timestep of the next event.
virtual void Run(void)
Run the simulation.
uint64_t m_currentTs
Execution context.
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
uint32_t m_uid
Unique id of the current event.
uint64_t m_eventCount
The event count.
uint32_t m_currentUid
Timestep of the current event.
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
void ScheduleRealtimeNowWithContext(uint32_t context, EventImpl *event)
Schedule an event to run at the current virtual time.
bool m_stop
Has the stopping condition been reached?
Ptr< Synchronizer > m_synchronizer
The synchronizer in use to track real time.
What to do when we can't maintain real time synchrony.
Make a best effort to keep synced to real-time.
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying.
Time m_hardLimit
The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual Time Now(void) const
Return the current simulation virtual time.
virtual uint32_t GetContext(void) const
Get the current simulation context.
bool Running(void) const
Is the simulator running?
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
void ProcessOneEvent(void)
Process the next event.
std::thread::id m_main
Main thread.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Set the SynchronizationMode.
virtual EventId ScheduleDestroy(EventImpl *event)
Schedule an event to run at the end of the simulation, after the Stop() time or condition has been re...
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
std::list< EventId > DestroyEvents
Container type for events to be run at destroy time.
Time RealtimeNow(void) const
Get the current real time from the synchronizer.
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
The SimulatorImpl base class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
a unique identifier for an interface.
Definition: type-id.h:59
ns3::EventImpl declarations.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::SimulatorImpl declaration.
ns3::Synchronizer declaration.