author | Tom Henderson <tomh@tomh.org> |
Fri, 18 Feb 2011 16:05:39 -0800 | |
changeset 6821 | 203367ae7433 |
parent 6493 | src/simulator/default-simulator-impl.cc@254056aee57b |
child 7169 | 358f71a624d8 |
permissions | -rw-r--r-- |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005,2006 INRIA |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
* |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
*/ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
#include "simulator.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "default-simulator-impl.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
#include "scheduler.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
#include "event-impl.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
#include "ns3/ptr.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
#include "ns3/pointer.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
#include "ns3/assert.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
#include "ns3/log.h" |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
#include <math.h> |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
NS_LOG_COMPONENT_DEFINE ("DefaultSimulatorImpl"); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
namespace ns3 { |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
NS_OBJECT_ENSURE_REGISTERED (DefaultSimulatorImpl); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
TypeId |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
DefaultSimulatorImpl::GetTypeId (void) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
static TypeId tid = TypeId ("ns3::DefaultSimulatorImpl") |
6493
254056aee57b
use proper parent classname
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6113
diff
changeset
|
43 |
.SetParent<SimulatorImpl> () |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
.AddConstructor<DefaultSimulatorImpl> () |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
return tid; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
DefaultSimulatorImpl::DefaultSimulatorImpl () |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
m_stop = false; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
// uids are allocated from 4. |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
// uid 0 is "invalid" events |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
// uid 1 is "now" events |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
// uid 2 is "destroy" events |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
56 |
m_uid = 4; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
// before ::Run is entered, the m_currentUid will be zero |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
m_currentUid = 0; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
m_currentTs = 0; |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
60 |
m_currentContext = 0xffffffff; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
m_unscheduledEvents = 0; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
DefaultSimulatorImpl::~DefaultSimulatorImpl () |
5872
188ecd74fcb4
It is not legal to call Dispose from within a destructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5521
diff
changeset
|
65 |
{} |
188ecd74fcb4
It is not legal to call Dispose from within a destructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5521
diff
changeset
|
66 |
|
188ecd74fcb4
It is not legal to call Dispose from within a destructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5521
diff
changeset
|
67 |
void |
188ecd74fcb4
It is not legal to call Dispose from within a destructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5521
diff
changeset
|
68 |
DefaultSimulatorImpl::DoDispose (void) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
while (!m_events->IsEmpty ()) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
{ |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
72 |
Scheduler::Event next = m_events->RemoveNext (); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
73 |
next.impl->Unref (); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
m_events = 0; |
5872
188ecd74fcb4
It is not legal to call Dispose from within a destructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
5521
diff
changeset
|
76 |
SimulatorImpl::DoDispose (); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
void |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
DefaultSimulatorImpl::Destroy () |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
while (!m_destroyEvents.empty ()) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
Ptr<EventImpl> ev = m_destroyEvents.front ().PeekEventImpl (); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
m_destroyEvents.pop_front (); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
NS_LOG_LOGIC ("handle destroy " << ev); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
if (!ev->IsCancelled ()) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
ev->Invoke (); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
void |
5507
915abd2b907b
Simulator::SetScheduler now takes an ObjectFactory
Guillaume Seguin <guillaume@segu.in>
parents:
5302
diff
changeset
|
94 |
DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
{ |
5507
915abd2b907b
Simulator::SetScheduler now takes an ObjectFactory
Guillaume Seguin <guillaume@segu.in>
parents:
5302
diff
changeset
|
96 |
Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> (); |
915abd2b907b
Simulator::SetScheduler now takes an ObjectFactory
Guillaume Seguin <guillaume@segu.in>
parents:
5302
diff
changeset
|
97 |
|
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
if (m_events != 0) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
while (!m_events->IsEmpty ()) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
{ |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
102 |
Scheduler::Event next = m_events->RemoveNext (); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
scheduler->Insert (next); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
m_events = scheduler; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
|
6113
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
109 |
// System ID for non-distributed simulation is always zero |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
110 |
uint32_t |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
111 |
DefaultSimulatorImpl::GetSystemId (void) const |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
112 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
113 |
return 0; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
114 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
5872
diff
changeset
|
115 |
|
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
void |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
DefaultSimulatorImpl::ProcessOneEvent (void) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
{ |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
119 |
Scheduler::Event next = m_events->RemoveNext (); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
|
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
121 |
NS_ASSERT (next.key.m_ts >= m_currentTs); |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
122 |
m_unscheduledEvents--; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
|
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
124 |
NS_LOG_LOGIC ("handle " << next.key.m_ts); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
125 |
m_currentTs = next.key.m_ts; |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
126 |
m_currentContext = next.key.m_context; |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
127 |
m_currentUid = next.key.m_uid; |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
128 |
next.impl->Invoke (); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
129 |
next.impl->Unref (); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
bool |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
DefaultSimulatorImpl::IsFinished (void) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
{ |
4085
31945ecb17e2
Make Simulator::IsFinished () take into account the stop time. Needed to run custom simulation loops (see bug 375)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4057
diff
changeset
|
135 |
return m_events->IsEmpty () || m_stop; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
uint64_t |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
DefaultSimulatorImpl::NextTs (void) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
NS_ASSERT (!m_events->IsEmpty ()); |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
142 |
Scheduler::Event ev = m_events->PeekNext (); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
143 |
return ev.key.m_ts; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
Time |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
DefaultSimulatorImpl::Next (void) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
return TimeStep (NextTs ()); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
void |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
DefaultSimulatorImpl::Run (void) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
{ |
4057
a68a42e667f6
bug 459: Simulator::Run does nothing after Simulator::Stop is called
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4009
diff
changeset
|
155 |
m_stop = false; |
4009
76cb8ed8fe98
fix bug 230, rescan bindings
mathieu.lacage@sophia.inria.fr
parents:
3816
diff
changeset
|
156 |
while (!m_events->IsEmpty () && !m_stop) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
ProcessOneEvent (); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
// If the simulator stopped naturally by lack of events, make a |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
162 |
// consistency test to check that we didn't lose any events along the way. |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
NS_ASSERT(!m_events->IsEmpty () || m_unscheduledEvents == 0); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
165 |
|
3515
88e9cee20461
Bug #270: Simulator::RunOneEvent
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3494
diff
changeset
|
166 |
void |
88e9cee20461
Bug #270: Simulator::RunOneEvent
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3494
diff
changeset
|
167 |
DefaultSimulatorImpl::RunOneEvent (void) |
88e9cee20461
Bug #270: Simulator::RunOneEvent
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3494
diff
changeset
|
168 |
{ |
88e9cee20461
Bug #270: Simulator::RunOneEvent
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3494
diff
changeset
|
169 |
ProcessOneEvent (); |
88e9cee20461
Bug #270: Simulator::RunOneEvent
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3494
diff
changeset
|
170 |
} |
88e9cee20461
Bug #270: Simulator::RunOneEvent
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
3494
diff
changeset
|
171 |
|
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
void |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
173 |
DefaultSimulatorImpl::Stop (void) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
174 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
m_stop = true; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
176 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
|
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
178 |
void |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
179 |
DefaultSimulatorImpl::Stop (Time const &time) |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
180 |
{ |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
181 |
Simulator::Schedule (time, &Simulator::Stop); |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
182 |
} |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
|
3796
75c6a3d424d9
make simulator schedule calls explicitly relative throughout. fixes multithread problem in realtime simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
184 |
// |
75c6a3d424d9
make simulator schedule calls explicitly relative throughout. fixes multithread problem in realtime simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
185 |
// Schedule an event for a _relative_ time in the future. |
75c6a3d424d9
make simulator schedule calls explicitly relative throughout. fixes multithread problem in realtime simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
186 |
// |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
EventId |
3808
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3807
diff
changeset
|
188 |
DefaultSimulatorImpl::Schedule (Time const &time, EventImpl *event) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
{ |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
190 |
Time tAbsolute = time + TimeStep (m_currentTs); |
3796
75c6a3d424d9
make simulator schedule calls explicitly relative throughout. fixes multithread problem in realtime simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
191 |
|
75c6a3d424d9
make simulator schedule calls explicitly relative throughout. fixes multithread problem in realtime simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
192 |
NS_ASSERT (tAbsolute.IsPositive ()); |
75c6a3d424d9
make simulator schedule calls explicitly relative throughout. fixes multithread problem in realtime simulator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3560
diff
changeset
|
193 |
NS_ASSERT (tAbsolute >= TimeStep (m_currentTs)); |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
194 |
Scheduler::Event ev; |
3808
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3807
diff
changeset
|
195 |
ev.impl = event; |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
196 |
ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep (); |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
197 |
ev.key.m_context = GetContext (); |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
198 |
ev.key.m_uid = m_uid; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
m_uid++; |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
200 |
m_unscheduledEvents++; |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
201 |
m_events->Insert (ev); |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
202 |
return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid); |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
203 |
} |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
204 |
|
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
205 |
void |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
206 |
DefaultSimulatorImpl::ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event) |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
207 |
{ |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
208 |
NS_LOG_FUNCTION (this << context << time.GetTimeStep () << m_currentTs << event); |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
209 |
|
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
210 |
Scheduler::Event ev; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
211 |
ev.impl = event; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
212 |
ev.key.m_ts = m_currentTs + time.GetTimeStep (); |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
213 |
ev.key.m_context = context; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
214 |
ev.key.m_uid = m_uid; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
215 |
m_uid++; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
216 |
m_unscheduledEvents++; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
217 |
m_events->Insert (ev); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
218 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
220 |
EventId |
3808
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3807
diff
changeset
|
221 |
DefaultSimulatorImpl::ScheduleNow (EventImpl *event) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
222 |
{ |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
223 |
Scheduler::Event ev; |
3808
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3807
diff
changeset
|
224 |
ev.impl = event; |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
225 |
ev.key.m_ts = m_currentTs; |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
226 |
ev.key.m_context = GetContext (); |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
227 |
ev.key.m_uid = m_uid; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
228 |
m_uid++; |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
229 |
m_unscheduledEvents++; |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
230 |
m_events->Insert (ev); |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
231 |
return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
232 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
233 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
234 |
EventId |
3808
ace932ee6eef
avoid using Ptr<EventImpl>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3807
diff
changeset
|
235 |
DefaultSimulatorImpl::ScheduleDestroy (EventImpl *event) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
{ |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
237 |
EventId id (Ptr<EventImpl> (event, false), m_currentTs, 0xffffffff, 2); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
238 |
m_destroyEvents.push_back (id); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
239 |
m_uid++; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
return id; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
241 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
242 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
243 |
Time |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
244 |
DefaultSimulatorImpl::Now (void) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
245 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
return TimeStep (m_currentTs); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
Time |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
250 |
DefaultSimulatorImpl::GetDelayLeft (const EventId &id) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
251 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
252 |
if (IsExpired (id)) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
253 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
254 |
return TimeStep (0); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
255 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
256 |
else |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
257 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
258 |
return TimeStep (id.GetTs () - m_currentTs); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
259 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
260 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
261 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
262 |
void |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
263 |
DefaultSimulatorImpl::Remove (const EventId &id) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
264 |
{ |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
265 |
if (id.GetUid () == 2) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
266 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
267 |
// destroy events. |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
268 |
for (DestroyEvents::iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
269 |
{ |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
270 |
if (*i == id) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
271 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
272 |
m_destroyEvents.erase (i); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
273 |
break; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
274 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
275 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
276 |
return; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
277 |
} |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
278 |
if (IsExpired (id)) |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
279 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
280 |
return; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
281 |
} |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
282 |
Scheduler::Event event; |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
283 |
event.impl = id.PeekEventImpl (); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
284 |
event.key.m_ts = id.GetTs (); |
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
285 |
event.key.m_context = id.GetContext (); |
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
286 |
event.key.m_uid = id.GetUid (); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
287 |
m_events->Remove (event); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
288 |
event.impl->Cancel (); |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
289 |
// whenever we remove an event from the event list, we have to unref it. |
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
290 |
event.impl->Unref (); |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
291 |
|
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
292 |
m_unscheduledEvents--; |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
293 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
294 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
295 |
void |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
296 |
DefaultSimulatorImpl::Cancel (const EventId &id) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
297 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
298 |
if (!IsExpired (id)) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
299 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
300 |
id.PeekEventImpl ()->Cancel (); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
301 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
302 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
303 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
304 |
bool |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
305 |
DefaultSimulatorImpl::IsExpired (const EventId &ev) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
306 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
307 |
if (ev.GetUid () == 2) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
308 |
{ |
5302
5ed72d440db4
fix old bug: canceled destroy events are expired
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4552
diff
changeset
|
309 |
if (ev.PeekEventImpl () == 0 || |
5ed72d440db4
fix old bug: canceled destroy events are expired
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4552
diff
changeset
|
310 |
ev.PeekEventImpl ()->IsCancelled ()) |
5ed72d440db4
fix old bug: canceled destroy events are expired
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4552
diff
changeset
|
311 |
{ |
5ed72d440db4
fix old bug: canceled destroy events are expired
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4552
diff
changeset
|
312 |
return true; |
5ed72d440db4
fix old bug: canceled destroy events are expired
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4552
diff
changeset
|
313 |
} |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
314 |
// destroy events. |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
315 |
for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
316 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
317 |
if (*i == ev) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
318 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
319 |
return false; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
320 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
321 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
322 |
return true; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
323 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
324 |
if (ev.PeekEventImpl () == 0 || |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
325 |
ev.GetTs () < m_currentTs || |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
326 |
(ev.GetTs () == m_currentTs && |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
327 |
ev.GetUid () <= m_currentUid) || |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
328 |
ev.PeekEventImpl ()->IsCancelled ()) |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
329 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
330 |
return true; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
331 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
332 |
else |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
333 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
334 |
return false; |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
335 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
336 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
337 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
338 |
Time |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
339 |
DefaultSimulatorImpl::GetMaximumSimulationTime (void) const |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
340 |
{ |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
341 |
// XXX: I am fairly certain other compilers use other non-standard |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
342 |
// post-fixes to indicate 64 bit constants. |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
343 |
return TimeStep (0x7fffffffffffffffLL); |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
344 |
} |
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
345 |
|
5521
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
346 |
uint32_t |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
347 |
DefaultSimulatorImpl::GetContext (void) const |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
348 |
{ |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
349 |
return m_currentContext; |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
350 |
} |
37c6c83d4252
Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents:
5507
diff
changeset
|
351 |
|
3807
268b86ce5435
don't use EventId in Schedulers: use Scheduler::Event instead.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3796
diff
changeset
|
352 |
} // namespace ns3 |
3470
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
353 |
|
21022872009d
make simulator implementation replaceable via global default value
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
354 |