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) 2005,2006 INRIA
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 *
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
24#include "simulator-impl.h"
25#include <list>
26#include <mutex>
27#include <thread>
35namespace ns3 {
37// Forward
38class Scheduler;
52 static TypeId GetTypeId (void);
59 // Inherited
60 virtual void Destroy ();
61 virtual bool IsFinished (void) const;
62 virtual void Stop (void);
63 virtual void Stop (const Time &delay);
64 virtual EventId Schedule (const Time &delay, EventImpl *event);
65 virtual void ScheduleWithContext (uint32_t context, const Time &delay, EventImpl *event);
66 virtual EventId ScheduleNow (EventImpl *event);
67 virtual EventId ScheduleDestroy (EventImpl *event);
68 virtual void Remove (const EventId &id);
69 virtual void Cancel (const EventId &id);
70 virtual bool IsExpired (const EventId &id) const;
71 virtual void Run (void);
72 virtual Time Now (void) const;
73 virtual Time GetDelayLeft (const EventId &id) const;
74 virtual Time GetMaximumSimulationTime (void) const;
75 virtual void SetScheduler (ObjectFactory schedulerFactory);
76 virtual uint32_t GetSystemId (void) const;
77 virtual uint32_t GetContext (void) const;
78 virtual uint64_t GetEventCount (void) const;
81 virtual void DoDispose (void);
84 void ProcessOneEvent (void);
86 void ProcessEventsWithContext (void);
90 {
94 uint64_t timestamp;
97 };
99 typedef std::list<struct EventWithContext> EventsWithContext;
111 typedef std::list<EventId> DestroyEvents;
115 bool m_stop;
124 uint64_t m_currentTs;
128 uint64_t m_eventCount;
136 std::thread::id m_mainThreadId;
139} // namespace ns3
The default single process simulator implementation.
bool m_stop
Flag calling for the end of the simulation.
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...
bool m_eventsWithContextEmpty
Flag true if all events with context have been moved to the primary event queue.
void ProcessEventsWithContext(void)
Move events from a different context into the main event queue.
uint32_t m_currentContext
Execution context of the current event.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
virtual void Remove(const EventId &id)
Remove an event from the event list.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
DestroyEvents m_destroyEvents
The container of events to run at Destroy.
virtual void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
virtual uint32_t GetContext(void) const
Get the current simulation context.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
Ptr< Scheduler > m_events
The event priority queue.
std::list< struct EventWithContext > EventsWithContext
Container type for the events from a different context.
void ProcessOneEvent(void)
Process the next event.
virtual void Run(void)
Run the simulation.
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
uint64_t m_currentTs
Timestamp of the current event.
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
uint64_t m_eventCount
The event count.
int m_unscheduledEvents
Number of events that have been inserted but not yet scheduled, not counting the Destroy events; this...
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
std::list< EventId > DestroyEvents
Container type for the events to run at Simulator::Destroy()
std::mutex m_eventsWithContextMutex
Mutex to control access to the list of events with context.
static TypeId GetTypeId(void)
Register this type.
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
virtual Time Now(void) const
Return the current simulation virtual time.
uint32_t m_uid
Next event unique id.
uint32_t m_currentUid
Unique id of the current event.
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual void DoDispose(void)
Destructor implementation.
std::thread::id m_mainThreadId
Main execution thread.
EventsWithContext m_eventsWithContext
The container of events from a different context.
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
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SimulatorImpl declaration.
Wrap an event with its execution context.
EventImpl * event
The event implementation.