1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2008 University of Washington
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;
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.
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
19 #ifndef REALTIME_SIMULATOR_IMPL_H
20 #define REALTIME_SIMULATOR_IMPL_H
22 #include "simulator-impl.h"
24 #include "scheduler.h"
25 #include "synchronizer.h"
26 #include "event-impl.h"
29 #include "ns3/assert.h"
31 #include "ns3/system-mutex.h"
37 class RealtimeSimulatorImpl : public SimulatorImpl
40 static TypeId GetTypeId (void);
43 * Enumeration of the types of packets supported in the class.
46 enum SynchronizationMode {
47 SYNC_BEST_EFFORT, /** Make a best effort to keep synced to real-time */
48 SYNC_HARD_LIMIT, /** Keep to real-time within a tolerance or die trying */
51 RealtimeSimulatorImpl ();
52 ~RealtimeSimulatorImpl ();
54 virtual void Destroy ();
55 virtual bool IsFinished (void) const;
56 virtual Time Next (void) const;
57 virtual void Stop (void);
58 virtual EventId Schedule (Time const &time, EventImpl *event);
59 virtual EventId ScheduleNow (EventImpl *event);
60 virtual EventId ScheduleDestroy (EventImpl *event);
61 virtual void Remove (const EventId &ev);
62 virtual void Cancel (const EventId &ev);
63 virtual bool IsExpired (const EventId &ev) const;
64 virtual void Run (void);
65 virtual void RunOneEvent (void);
66 virtual Time Now (void) const;
67 virtual Time GetDelayLeft (const EventId &id) const;
68 virtual Time GetMaximumSimulationTime (void) const;
69 virtual void SetScheduler (ObjectFactory schedulerFactory);
71 void ScheduleRealtime (Time const &time, EventImpl *event);
72 void ScheduleRealtimeNow (EventImpl *event);
73 Time RealtimeNow (void) const;
75 void SetSynchronizationMode (RealtimeSimulatorImpl::SynchronizationMode mode);
76 RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode (void) const;
78 void SetHardLimit (Time limit);
79 Time GetHardLimit (void) const;
82 bool Running (void) const;
83 bool Realtime (void) const;
85 void ProcessOneEvent (void);
86 uint64_t NextTs (void) const;
88 typedef std::list<EventId> DestroyEvents;
89 DestroyEvents m_destroyEvents;
93 // The following variables are protected using the m_mutex
94 Ptr<Scheduler> m_events;
95 int m_unscheduledEvents;
97 uint32_t m_currentUid;
100 mutable SystemMutex m_mutex;
102 Ptr<Synchronizer> m_synchronizer;
105 * The policy to use if the simulation cannot keep synchronized to real-time.
107 SynchronizationMode m_synchronizationMode;
110 * The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
117 #endif /* REALTIME_SIMULATOR_IMPL_H */