author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 27 Oct 2008 12:47:33 +0100 | |
changeset 3816 | edd4928b2046 |
parent 3812 | 6cca59a0fca6 |
child 4009 | 76cb8ed8fe98 |
permissions | -rw-r--r-- |
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2008 University of Washington |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
*/ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#ifndef REALTIME_SIMULATOR_IMPL_H |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
#define REALTIME_SIMULATOR_IMPL_H |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "simulator-impl.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
#include "scheduler.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
#include "synchronizer.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
#include "event-impl.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
#include "ns3/ptr.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
#include "ns3/assert.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
#include "ns3/log.h" |
3650
516c4f22d251
Missing include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3566
diff
changeset
|
31 |
#include "ns3/system-mutex.h" |
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
#include <list> |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
namespace ns3 { |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
class RealtimeSimulatorImpl : public SimulatorImpl |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
{ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
public: |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
static TypeId GetTypeId (void); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
/** |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
* Enumeration of the types of packets supported in the class. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
*/ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
enum SynchronizationMode { |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
SYNC_BEST_EFFORT, /** Make a best effort to keep synced to real-time */ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
SYNC_HARD_LIMIT, /** Keep to real-time within a tolerance or die trying */ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
}; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
RealtimeSimulatorImpl (); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
~RealtimeSimulatorImpl (); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
|
3808
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
54 |
virtual void Destroy (); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
55 |
virtual bool IsFinished (void) const; |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
56 |
virtual Time Next (void) const; |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
57 |
virtual void Stop (void); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
58 |
virtual void Stop (Time const &time); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
59 |
virtual EventId Schedule (Time const &time, EventImpl *event); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
60 |
virtual EventId ScheduleNow (EventImpl *event); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
61 |
virtual EventId ScheduleDestroy (EventImpl *event); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
62 |
virtual void Remove (const EventId &ev); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
63 |
virtual void Cancel (const EventId &ev); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
64 |
virtual bool IsExpired (const EventId &ev) const; |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
65 |
virtual void Run (void); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
66 |
virtual void RunOneEvent (void); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
67 |
virtual Time Now (void) const; |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
68 |
virtual Time GetDelayLeft (const EventId &id) const; |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
69 |
virtual Time GetMaximumSimulationTime (void) const; |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
70 |
virtual void SetScheduler (Ptr<Scheduler> scheduler); |
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3801
diff
changeset
|
71 |
virtual Ptr<Scheduler> GetScheduler (void) const; |
3809
5e007004402e
move MakeEvent out of Simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3808
diff
changeset
|
72 |
|
3816
edd4928b2046
remove realtime public API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3812
diff
changeset
|
73 |
void ScheduleRealtime (Time const &time, EventImpl *event); |
edd4928b2046
remove realtime public API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3812
diff
changeset
|
74 |
void ScheduleRealtimeNow (EventImpl *event); |
3801
dc1f5e534e56
slight reorganization and naming change for added realtime methods
Craig Dowell <craigdo@ee.washington.edu>
parents:
3798
diff
changeset
|
75 |
Time RealtimeNow (void) const; |
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
void SetSynchronizationMode (RealtimeSimulatorImpl::SynchronizationMode mode); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode (void) const; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
void SetHardLimit (Time limit); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
Time GetHardLimit (void) const; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
private: |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
bool Running (void) const; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
bool Realtime (void) const; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
void ProcessOneEvent (void); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
uint64_t NextTs (void) const; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
typedef std::list<EventId> DestroyEvents; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
DestroyEvents m_destroyEvents; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
uint64_t m_stopAt; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
bool m_stop; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
bool m_running; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
// The following variables are protected using the m_mutex |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
Ptr<Scheduler> m_events; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
int m_unscheduledEvents; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
uint32_t m_uid; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
uint32_t m_currentUid; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
uint64_t m_currentTs; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
mutable SystemMutex m_mutex; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
Ptr<Synchronizer> m_synchronizer; |
3561
e388935fa948
ifdef out ability to feed real-time through simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
106 |
|
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
/** |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
* The policy to use if the simulation cannot keep synchronized to real-time. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
*/ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
SynchronizationMode m_synchronizationMode; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
/** |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
* The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
*/ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
Time m_hardLimit; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
}; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
} // namespace ns3 |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
#endif /* REALTIME_SIMULATOR_IMPL_H */ |