00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "simulator.h"
00022 #include "simulator-impl.h"
00023 #include "default-simulator-impl.h"
00024 #include "realtime-simulator-impl.h"
00025 #include "scheduler.h"
00026 #include "event-impl.h"
00027
00028 #include "ns3/ptr.h"
00029 #include "ns3/string.h"
00030 #include "ns3/object-factory.h"
00031 #include "ns3/global-value.h"
00032 #include "ns3/assert.h"
00033 #include "ns3/log.h"
00034
00035 #include <math.h>
00036 #include <fstream>
00037 #include <list>
00038 #include <vector>
00039 #include <iostream>
00040
00041 NS_LOG_COMPONENT_DEFINE ("Simulator");
00042
00043 namespace ns3 {
00044
00045 GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType",
00046 "The object class to use as the simulator implementation",
00047 StringValue ("ns3::DefaultSimulatorImpl"),
00048 MakeStringChecker ());
00049
00050 GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType",
00051 "The object class to use as the scheduler implementation",
00052 StringValue ("ns3::MapScheduler"),
00053 MakeStringChecker ());
00054
00055
00056 #ifdef NS3_LOG_ENABLE
00057
00058
00059
00060
00061
00062
00063 static void
00064 TimePrinter (std::ostream &os)
00065 {
00066 os << Simulator::Now ().GetSeconds () << "s";
00067 }
00068
00069 #endif
00070
00071 static Ptr<SimulatorImpl> *PeekImpl (void)
00072 {
00073 static Ptr<SimulatorImpl> impl = 0;
00074 return &impl;
00075 }
00076
00077 static SimulatorImpl * GetImpl (void)
00078 {
00079 Ptr<SimulatorImpl> &impl = *PeekImpl ();
00080
00081
00082
00083 if (impl == 0)
00084 {
00085 {
00086 ObjectFactory factory;
00087 StringValue s;
00088
00089 g_simTypeImpl.GetValue (s);
00090 factory.SetTypeId (s.Get ());
00091 impl = factory.Create<SimulatorImpl> ();
00092 }
00093 {
00094 ObjectFactory factory;
00095 StringValue s;
00096 g_schedTypeImpl.GetValue (s);
00097 factory.SetTypeId (s.Get ());
00098 impl->SetScheduler (factory.Create<Scheduler> ());
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108 LogSetTimePrinter (&TimePrinter);
00109 }
00110 return PeekPointer (impl);
00111 }
00112
00113 void
00114 Simulator::Destroy (void)
00115 {
00116 NS_LOG_FUNCTION_NOARGS ();
00117
00118 Ptr<SimulatorImpl> &impl = *PeekImpl ();
00119 if (impl == 0)
00120 {
00121 return;
00122 }
00123
00124
00125
00126
00127
00128 LogSetTimePrinter (0);
00129 impl->Destroy ();
00130 impl = 0;
00131 }
00132
00133 void
00134 Simulator::SetScheduler (Ptr<Scheduler> scheduler)
00135 {
00136 NS_LOG_FUNCTION (scheduler);
00137 GetImpl ()->SetScheduler (scheduler);
00138 }
00139
00140 void
00141 Simulator::EnableLogTo (char const *filename)
00142 {}
00143
00144 bool
00145 Simulator::IsFinished (void)
00146 {
00147 NS_LOG_FUNCTION_NOARGS ();
00148 return GetImpl ()->IsFinished ();
00149 }
00150
00151 Time
00152 Simulator::Next (void)
00153 {
00154 NS_LOG_FUNCTION_NOARGS ();
00155 return GetImpl ()->Next ();
00156 }
00157
00158 void
00159 Simulator::Run (void)
00160 {
00161 NS_LOG_FUNCTION_NOARGS ();
00162 GetImpl ()->Run ();
00163 }
00164
00165 void
00166 Simulator::RunOneEvent (void)
00167 {
00168 NS_LOG_FUNCTION_NOARGS ();
00169 GetImpl ()->RunOneEvent ();
00170 }
00171
00172 void
00173 Simulator::Stop (void)
00174 {
00175 NS_LOG_LOGIC ("stop");
00176 GetImpl ()->Stop ();
00177 }
00178
00179 void
00180 Simulator::Stop (Time const &time)
00181 {
00182 NS_LOG_FUNCTION (time);
00183 Simulator::Schedule (time, &Simulator::Stop);
00184 }
00185
00186 Time
00187 Simulator::Now (void)
00188 {
00189
00190
00191
00192 return GetImpl ()->Now ();
00193 }
00194
00195 Time
00196 Simulator::GetDelayLeft (const EventId &id)
00197 {
00198 NS_LOG_FUNCTION (&id);
00199 return GetImpl ()->GetDelayLeft (id);
00200 }
00201
00202 EventId
00203 Simulator::Schedule (Time const &time, const Ptr<EventImpl> &ev)
00204 {
00205 NS_LOG_FUNCTION (time << ev);
00206 return DoSchedule (time, GetPointer (ev));
00207 }
00208
00209 EventId
00210 Simulator::ScheduleNow (const Ptr<EventImpl> &ev)
00211 {
00212 NS_LOG_FUNCTION (ev);
00213 return DoScheduleNow (GetPointer (ev));
00214 }
00215
00216 EventId
00217 Simulator::ScheduleDestroy (const Ptr<EventImpl> &ev)
00218 {
00219 NS_LOG_FUNCTION (ev);
00220 return DoScheduleDestroy (GetPointer (ev));
00221 }
00222 EventId
00223 Simulator::DoSchedule (Time const &time, EventImpl *impl)
00224 {
00225 return GetImpl ()->Schedule (time, impl);
00226 }
00227 EventId
00228 Simulator::DoScheduleNow (EventImpl *impl)
00229 {
00230 return GetImpl ()->ScheduleNow (impl);
00231 }
00232 EventId
00233 Simulator::DoScheduleDestroy (EventImpl *impl)
00234 {
00235 return GetImpl ()->ScheduleDestroy (impl);
00236 }
00237
00238
00239 EventId
00240 Simulator::Schedule (Time const &time, void (*f) (void))
00241 {
00242 NS_LOG_FUNCTION (time << f);
00243 return DoSchedule (time, MakeEvent (f));
00244 }
00245
00246 EventId
00247 Simulator::ScheduleNow (void (*f) (void))
00248 {
00249 NS_LOG_FUNCTION (f);
00250 return DoScheduleNow (MakeEvent (f));
00251 }
00252
00253 EventId
00254 Simulator::ScheduleDestroy (void (*f) (void))
00255 {
00256 NS_LOG_FUNCTION (f);
00257 return DoScheduleDestroy (MakeEvent (f));
00258 }
00259
00260 void
00261 Simulator::Remove (const EventId &ev)
00262 {
00263 NS_LOG_FUNCTION (&ev);
00264 return GetImpl ()->Remove (ev);
00265 }
00266
00267 void
00268 Simulator::Cancel (const EventId &ev)
00269 {
00270 NS_LOG_FUNCTION (&ev);
00271 return GetImpl ()->Cancel (ev);
00272 }
00273
00274 bool
00275 Simulator::IsExpired (const EventId &id)
00276 {
00277 NS_LOG_FUNCTION (&id);
00278 return GetImpl ()->IsExpired (id);
00279 }
00280
00281 Time Now (void)
00282 {
00283 NS_LOG_FUNCTION_NOARGS ();
00284 return Time (Simulator::Now ());
00285 }
00286
00287 Time
00288 Simulator::GetMaximumSimulationTime (void)
00289 {
00290 NS_LOG_FUNCTION_NOARGS ();
00291 return GetImpl ()->GetMaximumSimulationTime ();
00292 }
00293
00294 void
00295 Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
00296 {
00297 NS_FATAL_ERROR ("TODO");
00298 }
00299 Ptr<SimulatorImpl>
00300 Simulator::GetImplementation (void)
00301 {
00302 return GetImpl ();
00303 }
00304
00305
00306
00307 }
00308
00309
00310 #ifdef RUN_SELF_TESTS
00311
00312 #include "ns3/test.h"
00313 #include "ns3/ptr.h"
00314 #include "list-scheduler.h"
00315 #include "heap-scheduler.h"
00316 #include "map-scheduler.h"
00317
00318 namespace ns3 {
00319
00320 static void foo0 (void)
00321 {}
00322 static void foo1 (int)
00323 {}
00324 static void foo2 (int, int)
00325 {}
00326 static void foo3 (int, int, int)
00327 {}
00328 static void foo4 (int, int, int, int)
00329 {}
00330 static void foo5 (int, int, int, int, int)
00331 {}
00332
00333 #if 1
00334 static void ber1 (int &)
00335 {}
00336 static void ber2 (int &, int &)
00337 {}
00338 static void ber3 (int &, int &, int &)
00339 {}
00340 static void ber4 (int &, int &, int &, int &)
00341 {}
00342 static void ber5 (int &, int &, int &, int &, int &)
00343 {}
00344 #endif
00345
00346 static void cber1 (const int &)
00347 {}
00348 static void cber2 (const int &, const int &)
00349 {}
00350 static void cber3 (const int &, const int &, const int &)
00351 {}
00352 static void cber4 (const int &, const int &, const int &, const int &)
00353 {}
00354 static void cber5 (const int &, const int &, const int &, const int &, const int &)
00355 {}
00356
00357
00358 class SimulatorTests : public Test
00359 {
00360 public:
00361 SimulatorTests ();
00362
00363 void Ref (void) const;
00364 void Unref (void) const;
00365 virtual ~SimulatorTests ();
00366 virtual bool RunTests (void);
00367 private:
00368 uint64_t NowUs ();
00369 bool RunOneTest (void);
00370 void RunTestsConst (void) const;
00371 void A (int a);
00372 void B (int b);
00373 void C (int c);
00374 void D (int d);
00375 void bar0 (void);
00376 void bar1 (int);
00377 void bar2 (int, int);
00378 void bar3 (int, int, int);
00379 void bar4 (int, int, int, int);
00380 void bar5 (int, int, int, int, int);
00381 void baz1 (int &);
00382 void baz2 (int &, int &);
00383 void baz3 (int &, int &, int &);
00384 void baz4 (int &, int &, int &, int &);
00385 void baz5 (int &, int &, int &, int &, int &);
00386 void cbaz1 (const int &);
00387 void cbaz2 (const int &, const int &);
00388 void cbaz3 (const int &, const int &, const int &);
00389 void cbaz4 (const int &, const int &, const int &, const int &);
00390 void cbaz5 (const int &, const int &, const int &, const int &, const int &);
00391
00392 void bar0c (void) const;
00393 void bar1c (int) const;
00394 void bar2c (int, int) const;
00395 void bar3c (int, int, int) const;
00396 void bar4c (int, int, int, int) const;
00397 void bar5c (int, int, int, int, int) const;
00398 void baz1c (int &) const;
00399 void baz2c (int &, int &) const;
00400 void baz3c (int &, int &, int &) const;
00401 void baz4c (int &, int &, int &, int &) const;
00402 void baz5c (int &, int &, int &, int &, int &) const;
00403 void cbaz1c (const int &) const;
00404 void cbaz2c (const int &, const int &) const;
00405 void cbaz3c (const int &, const int &, const int &) const;
00406 void cbaz4c (const int &, const int &, const int &, const int &) const;
00407 void cbaz5c (const int &, const int &, const int &, const int &, const int &) const;
00408
00409 void destroy (void);
00410
00411 bool m_b;
00412 bool m_a;
00413 bool m_c;
00414 bool m_d;
00415 EventId m_idC;
00416 bool m_destroy;
00417 EventId m_destroyId;
00418 };
00419
00420 SimulatorTests::SimulatorTests ()
00421 : Test ("Simulator")
00422 {}
00423
00424 SimulatorTests::~SimulatorTests ()
00425 {}
00426
00427 void
00428 SimulatorTests::Ref (void) const
00429 {}
00430
00431 void
00432 SimulatorTests::Unref (void) const
00433 {}
00434
00435 uint64_t
00436 SimulatorTests::NowUs (void)
00437 {
00438 uint64_t ns = Now ().GetNanoSeconds ();
00439 return ns / 1000;
00440 }
00441
00442 void
00443 SimulatorTests::A (int a)
00444 {
00445 m_a = false;
00446 }
00447
00448 void
00449 SimulatorTests::B (int b)
00450 {
00451 if (b != 2 || NowUs () != 11)
00452 {
00453 m_b = false;
00454 }
00455 else
00456 {
00457 m_b = true;
00458 }
00459 Simulator::Remove (m_idC);
00460 Simulator::Schedule (MicroSeconds (10), &SimulatorTests::D, this, 4);
00461 }
00462
00463 void
00464 SimulatorTests::C (int c)
00465 {
00466 m_c = false;
00467 }
00468
00469 void
00470 SimulatorTests::D (int d)
00471 {
00472 if (d != 4 || NowUs () != (11+10))
00473 {
00474 m_d = false;
00475 }
00476 else
00477 {
00478 m_d = true;
00479 }
00480 }
00481
00482 void
00483 SimulatorTests::destroy (void)
00484 {
00485 if (m_destroyId.IsExpired ())
00486 {
00487 m_destroy = true;
00488 }
00489 }
00490
00491 void
00492 SimulatorTests::bar0 (void)
00493 {}
00494
00495 void
00496 SimulatorTests::bar1 (int)
00497 {}
00498
00499 void
00500 SimulatorTests::bar2 (int, int)
00501 {}
00502
00503 void
00504 SimulatorTests::bar3 (int, int, int)
00505 {}
00506
00507 void
00508 SimulatorTests::bar4 (int, int, int, int)
00509 {}
00510
00511 void
00512 SimulatorTests::bar5 (int, int, int, int, int)
00513 {}
00514
00515 void
00516 SimulatorTests::baz1 (int &)
00517 {}
00518
00519 void
00520 SimulatorTests::baz2 (int &, int &)
00521 {}
00522
00523 void
00524 SimulatorTests::baz3 (int &, int &, int &)
00525 {}
00526
00527 void
00528 SimulatorTests::baz4 (int &, int &, int &, int &)
00529 {}
00530
00531 void
00532 SimulatorTests::baz5 (int &, int &, int &, int &, int &)
00533 {}
00534
00535 void
00536 SimulatorTests::cbaz1 (const int &)
00537 {}
00538
00539 void
00540 SimulatorTests::cbaz2 (const int &, const int &)
00541 {}
00542
00543 void
00544 SimulatorTests::cbaz3 (const int &, const int &, const int &)
00545 {}
00546
00547 void
00548 SimulatorTests::cbaz4 (const int &, const int &, const int &, const int &)
00549 {}
00550
00551 void
00552 SimulatorTests::cbaz5 (const int &, const int &, const int &, const int &, const int &)
00553 {}
00554
00555 void
00556 SimulatorTests::bar0c (void) const
00557 {}
00558
00559 void
00560 SimulatorTests::bar1c (int) const
00561 {}
00562
00563 void
00564 SimulatorTests::bar2c (int, int) const
00565 {}
00566
00567 void
00568 SimulatorTests::bar3c (int, int, int) const
00569 {}
00570
00571 void
00572 SimulatorTests::bar4c (int, int, int, int) const
00573 {}
00574
00575 void
00576 SimulatorTests::bar5c (int, int, int, int, int) const
00577 {}
00578
00579 void
00580 SimulatorTests::baz1c (int &) const
00581 {}
00582
00583 void
00584 SimulatorTests::baz2c (int &, int &) const
00585 {}
00586
00587 void
00588 SimulatorTests::baz3c (int &, int &, int &) const
00589 {}
00590
00591 void
00592 SimulatorTests::baz4c (int &, int &, int &, int &) const
00593 {}
00594
00595 void
00596 SimulatorTests::baz5c (int &, int &, int &, int &, int &) const
00597 {}
00598
00599 void
00600 SimulatorTests::cbaz1c (const int &) const
00601 {}
00602
00603 void
00604 SimulatorTests::cbaz2c (const int &, const int &) const
00605 {}
00606
00607 void
00608 SimulatorTests::cbaz3c (const int &, const int &, const int &) const
00609 {}
00610
00611 void
00612 SimulatorTests::cbaz4c (const int &, const int &, const int &, const int &) const
00613 {}
00614
00615 void
00616 SimulatorTests::cbaz5c (const int &, const int &, const int &, const int &, const int &) const
00617 {}
00618
00619 bool
00620 SimulatorTests::RunOneTest (void)
00621 {
00622 bool result = true;
00623 m_a = true;
00624 m_b = false;
00625 m_c = true;
00626 m_d = false;
00627
00628 EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorTests::A, this, 1);
00629 Simulator::Schedule (MicroSeconds (11), &SimulatorTests::B, this, 2);
00630 m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorTests::C, this, 3);
00631
00632 NS_TEST_ASSERT (!m_idC.IsExpired ());
00633 NS_TEST_ASSERT (!a.IsExpired ());
00634 Simulator::Cancel (a);
00635 NS_TEST_ASSERT (a.IsExpired ());
00636 Simulator::Run ();
00637 NS_TEST_ASSERT (m_a);
00638 NS_TEST_ASSERT (m_b);
00639 NS_TEST_ASSERT (m_c);
00640 NS_TEST_ASSERT (m_d);
00641 return result;
00642 }
00643
00644 void
00645 SimulatorTests::RunTestsConst (void) const
00646 {
00647 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0c, this);
00648 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1c, this, 0);
00649 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2c, this, 0, 0);
00650 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3c, this, 0, 0, 0);
00651 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4c, this, 0, 0, 0, 0);
00652 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5c, this, 0, 0, 0, 0, 0);
00653 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0c, Ptr<const SimulatorTests> (this));
00654 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1c, Ptr<const SimulatorTests> (this), 0);
00655 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2c, Ptr<const SimulatorTests> (this), 0, 0);
00656 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3c, Ptr<const SimulatorTests> (this), 0, 0, 0);
00657 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0);
00658 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0, 0);
00659 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz1c, this, 0);
00660 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz2c, this, 0, 0);
00661 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz3c, this, 0, 0, 0);
00662 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz4c, this, 0, 0, 0, 0);
00663 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0);
00664 Simulator::ScheduleNow (&SimulatorTests::bar0c, this);
00665 Simulator::ScheduleNow (&SimulatorTests::bar1c, this, 0);
00666 Simulator::ScheduleNow (&SimulatorTests::bar2c, this, 0, 0);
00667 Simulator::ScheduleNow (&SimulatorTests::bar3c, this, 0, 0, 0);
00668 Simulator::ScheduleNow (&SimulatorTests::bar4c, this, 0, 0, 0, 0);
00669 Simulator::ScheduleNow (&SimulatorTests::bar5c, this, 0, 0, 0, 0, 0);
00670 Simulator::ScheduleNow (&SimulatorTests::cbaz1c, this, 0);
00671 Simulator::ScheduleNow (&SimulatorTests::cbaz2c, this, 0, 0);
00672 Simulator::ScheduleNow (&SimulatorTests::cbaz3c, this, 0, 0, 0);
00673 Simulator::ScheduleNow (&SimulatorTests::cbaz4c, this, 0, 0, 0, 0);
00674 Simulator::ScheduleNow (&SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0);
00675 Simulator::ScheduleNow (&SimulatorTests::bar0c, Ptr<const SimulatorTests> (this));
00676 Simulator::ScheduleNow (&SimulatorTests::bar1c, Ptr<const SimulatorTests> (this), 0);
00677 Simulator::ScheduleNow (&SimulatorTests::bar2c, Ptr<const SimulatorTests> (this), 0, 0);
00678 Simulator::ScheduleNow (&SimulatorTests::bar3c, Ptr<const SimulatorTests> (this), 0, 0, 0);
00679 Simulator::ScheduleNow (&SimulatorTests::bar4c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0);
00680 Simulator::ScheduleNow (&SimulatorTests::bar5c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0, 0);
00681 Simulator::ScheduleDestroy (&SimulatorTests::bar0c, this);
00682 Simulator::ScheduleDestroy (&SimulatorTests::bar1c, this, 0);
00683 Simulator::ScheduleDestroy (&SimulatorTests::bar2c, this, 0, 0);
00684 Simulator::ScheduleDestroy (&SimulatorTests::bar3c, this, 0, 0, 0);
00685 Simulator::ScheduleDestroy (&SimulatorTests::bar4c, this, 0, 0, 0, 0);
00686 Simulator::ScheduleDestroy (&SimulatorTests::bar5c, this, 0, 0, 0, 0, 0);
00687 Simulator::ScheduleDestroy (&SimulatorTests::cbaz1c, this, 0);
00688 Simulator::ScheduleDestroy (&SimulatorTests::cbaz2c, this, 0, 0);
00689 Simulator::ScheduleDestroy (&SimulatorTests::cbaz3c, this, 0, 0, 0);
00690 Simulator::ScheduleDestroy (&SimulatorTests::cbaz4c, this, 0, 0, 0, 0);
00691 Simulator::ScheduleDestroy (&SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0);
00692 Simulator::ScheduleDestroy (&SimulatorTests::bar0c, Ptr<const SimulatorTests> (this));
00693 Simulator::ScheduleDestroy (&SimulatorTests::bar1c, Ptr<const SimulatorTests> (this), 0);
00694 Simulator::ScheduleDestroy (&SimulatorTests::bar2c, Ptr<const SimulatorTests> (this), 0, 0);
00695 Simulator::ScheduleDestroy (&SimulatorTests::bar3c, Ptr<const SimulatorTests> (this), 0, 0, 0);
00696 Simulator::ScheduleDestroy (&SimulatorTests::bar4c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0);
00697 Simulator::ScheduleDestroy (&SimulatorTests::bar5c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0, 0);
00698 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz1c, this, 0);
00699 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz2c, this, 0, 0);
00700 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz3c, this, 0, 0, 0);
00701 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz4c, this, 0, 0, 0, 0);
00702 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz5c, this, 0, 0, 0, 0, 0);
00703 Simulator::ScheduleNow (&SimulatorTests::baz1c, this, 0);
00704 Simulator::ScheduleNow (&SimulatorTests::baz2c, this, 0, 0);
00705 Simulator::ScheduleNow (&SimulatorTests::baz3c, this, 0, 0, 0);
00706 Simulator::ScheduleNow (&SimulatorTests::baz4c, this, 0, 0, 0, 0);
00707 Simulator::ScheduleNow (&SimulatorTests::baz5c, this, 0, 0, 0, 0, 0);
00708 Simulator::ScheduleDestroy (&SimulatorTests::baz1c, this, 0);
00709 Simulator::ScheduleDestroy (&SimulatorTests::baz2c, this, 0, 0);
00710 Simulator::ScheduleDestroy (&SimulatorTests::baz3c, this, 0, 0, 0);
00711 Simulator::ScheduleDestroy (&SimulatorTests::baz4c, this, 0, 0, 0, 0);
00712 Simulator::ScheduleDestroy (&SimulatorTests::baz5c, this, 0, 0, 0, 0, 0);
00713
00714 Simulator::Run ();
00715 Simulator::Destroy ();
00716 }
00717
00718 bool
00719 SimulatorTests::RunTests (void)
00720 {
00721 bool result = true;
00722
00723 Simulator::Destroy ();
00724 Simulator::SetScheduler (CreateObject<ListScheduler> ());
00725 if (!RunOneTest ())
00726 {
00727 result = false;
00728 }
00729 Simulator::Destroy ();
00730 Simulator::SetScheduler (CreateObject<HeapScheduler> ());
00731 if (!RunOneTest ())
00732 {
00733 result = false;
00734 }
00735 Simulator::Destroy ();
00736 Simulator::SetScheduler (CreateObject<MapScheduler> ());
00737 if (!RunOneTest ())
00738 {
00739 result = false;
00740 }
00741 Simulator::Destroy ();
00742
00743 Simulator::Schedule (Seconds (0.0), &foo0);
00744 Simulator::Schedule (Seconds (0.0), &foo1, 0);
00745 Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
00746 Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
00747 Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
00748 Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
00749 Simulator::Schedule (Seconds (0.0), &cber1, 0);
00750 Simulator::Schedule (Seconds (0.0), &cber2, 0, 0);
00751 Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
00752 Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
00753 Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
00754 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this);
00755 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0);
00756 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0);
00757 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0);
00758 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0);
00759 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
00760 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, Ptr<SimulatorTests> (this));
00761 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, Ptr<SimulatorTests> (this), 0);
00762 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, Ptr<SimulatorTests> (this), 0, 0);
00763 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, Ptr<SimulatorTests> (this), 0, 0, 0);
00764 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, Ptr<SimulatorTests> (this), 0, 0, 0, 0);
00765 Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, Ptr<SimulatorTests> (this), 0, 0, 0, 0, 0);
00766 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz1, this, 0);
00767 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz2, this, 0, 0);
00768 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz3, this, 0, 0, 0);
00769 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz4, this, 0, 0, 0, 0);
00770 Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0);
00771 Simulator::ScheduleNow (&foo0);
00772 Simulator::ScheduleNow (&foo1, 0);
00773 Simulator::ScheduleNow (&foo2, 0, 0);
00774 Simulator::ScheduleNow (&foo3, 0, 0, 0);
00775 Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
00776 Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
00777 Simulator::ScheduleNow (&cber1, 0);
00778 Simulator::ScheduleNow (&cber2, 0, 0);
00779 Simulator::ScheduleNow (&cber3, 0, 0, 0);
00780 Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
00781 Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
00782 Simulator::ScheduleNow (&SimulatorTests::bar0, this);
00783 Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0);
00784 Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0);
00785 Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0);
00786 Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0);
00787 Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
00788 Simulator::ScheduleNow (&SimulatorTests::cbaz1, this, 0);
00789 Simulator::ScheduleNow (&SimulatorTests::cbaz2, this, 0, 0);
00790 Simulator::ScheduleNow (&SimulatorTests::cbaz3, this, 0, 0, 0);
00791 Simulator::ScheduleNow (&SimulatorTests::cbaz4, this, 0, 0, 0, 0);
00792 Simulator::ScheduleNow (&SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0);
00793 Simulator::ScheduleNow (&SimulatorTests::bar0, Ptr<SimulatorTests> (this));
00794 Simulator::ScheduleNow (&SimulatorTests::bar1, Ptr<SimulatorTests> (this), 0);
00795 Simulator::ScheduleNow (&SimulatorTests::bar2, Ptr<SimulatorTests> (this), 0, 0);
00796 Simulator::ScheduleNow (&SimulatorTests::bar3, Ptr<SimulatorTests> (this), 0, 0, 0);
00797 Simulator::ScheduleNow (&SimulatorTests::bar4, Ptr<SimulatorTests> (this), 0, 0, 0, 0);
00798 Simulator::ScheduleNow (&SimulatorTests::bar5, Ptr<SimulatorTests> (this), 0, 0, 0, 0, 0);
00799 Simulator::ScheduleDestroy (&foo0);
00800 Simulator::ScheduleDestroy (&foo1, 0);
00801 Simulator::ScheduleDestroy (&foo2, 0, 0);
00802 Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
00803 Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
00804 Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
00805 Simulator::ScheduleDestroy (&cber1, 0);
00806 Simulator::ScheduleDestroy (&cber2, 0, 0);
00807 Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
00808 Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
00809 Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
00810 Simulator::ScheduleDestroy (&SimulatorTests::bar0, this);
00811 Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0);
00812 Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0);
00813 Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0);
00814 Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0);
00815 Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
00816 Simulator::ScheduleDestroy (&SimulatorTests::cbaz1, this, 0);
00817 Simulator::ScheduleDestroy (&SimulatorTests::cbaz2, this, 0, 0);
00818 Simulator::ScheduleDestroy (&SimulatorTests::cbaz3, this, 0, 0, 0);
00819 Simulator::ScheduleDestroy (&SimulatorTests::cbaz4, this, 0, 0, 0, 0);
00820 Simulator::ScheduleDestroy (&SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0);
00821 Simulator::ScheduleDestroy (&SimulatorTests::bar0, Ptr<SimulatorTests> (this));
00822 Simulator::ScheduleDestroy (&SimulatorTests::bar1, Ptr<SimulatorTests> (this), 0);
00823 Simulator::ScheduleDestroy (&SimulatorTests::bar2, Ptr<SimulatorTests> (this), 0, 0);
00824 Simulator::ScheduleDestroy (&SimulatorTests::bar3, Ptr<SimulatorTests> (this), 0, 0, 0);
00825 Simulator::ScheduleDestroy (&SimulatorTests::bar4, Ptr<SimulatorTests> (this), 0, 0, 0, 0);
00826 Simulator::ScheduleDestroy (&SimulatorTests::bar5, Ptr<SimulatorTests> (this), 0, 0, 0, 0, 0);
00827
00828
00829
00830
00831
00832 #if 1
00833 Simulator::Schedule (Seconds (0.0), &ber1, 0);
00834 Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
00835 Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
00836 Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
00837 Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
00838 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz1, this, 0);
00839 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz2, this, 0, 0);
00840 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz3, this, 0, 0, 0);
00841 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz4, this, 0, 0, 0, 0);
00842 Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz5, this, 0, 0, 0, 0, 0);
00843 Simulator::ScheduleNow (&ber1, 0);
00844 Simulator::ScheduleNow (&ber2, 0, 0);
00845 Simulator::ScheduleNow (&ber3, 0, 0, 0);
00846 Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
00847 Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
00848 Simulator::ScheduleNow (&SimulatorTests::baz1, this, 0);
00849 Simulator::ScheduleNow (&SimulatorTests::baz2, this, 0, 0);
00850 Simulator::ScheduleNow (&SimulatorTests::baz3, this, 0, 0, 0);
00851 Simulator::ScheduleNow (&SimulatorTests::baz4, this, 0, 0, 0, 0);
00852 Simulator::ScheduleNow (&SimulatorTests::baz5, this, 0, 0, 0, 0, 0);
00853 Simulator::ScheduleDestroy (&ber1, 0);
00854 Simulator::ScheduleDestroy (&ber2, 0, 0);
00855 Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
00856 Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
00857 Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
00858 Simulator::ScheduleDestroy (&SimulatorTests::baz1, this, 0);
00859 Simulator::ScheduleDestroy (&SimulatorTests::baz2, this, 0, 0);
00860 Simulator::ScheduleDestroy (&SimulatorTests::baz3, this, 0, 0, 0);
00861 Simulator::ScheduleDestroy (&SimulatorTests::baz4, this, 0, 0, 0, 0);
00862 Simulator::ScheduleDestroy (&SimulatorTests::baz5, this, 0, 0, 0, 0, 0);
00863 #endif
00864
00865 RunTestsConst ();
00866
00867 EventId nowId = Simulator::ScheduleNow (&foo0);
00868 m_destroyId = Simulator::ScheduleDestroy (&SimulatorTests::destroy, this);
00869 NS_TEST_ASSERT (!m_destroyId.IsExpired ());
00870
00871 Simulator::Run ();
00872 m_destroy = false;
00873 Simulator::Destroy ();
00874 NS_TEST_ASSERT (m_destroy);
00875
00876 EventId anId = Simulator::ScheduleNow (&foo0);
00877 EventId anotherId = anId;
00878 NS_TEST_ASSERT (!(anId.IsExpired () || anotherId.IsExpired ()));
00879
00880 Simulator::Remove (anId);
00881 NS_TEST_ASSERT (anId.IsExpired ());
00882 NS_TEST_ASSERT (anotherId.IsExpired ());
00883
00884 Simulator::Run ();
00885 Simulator::Destroy ();
00886
00887 Simulator::Schedule (Seconds (10.0), &SimulatorTests::baz1, this, 0);
00888 Simulator::Stop (Seconds (1.0));
00889 Simulator::Run ();
00890 Simulator::Destroy ();
00891
00892 return result;
00893 }
00894
00895 SimulatorTests gSimulatorTests;
00896
00897 };
00898
00899 #endif
00900
00901
00902