1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2005,2006 INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 #include "ns3/core-config.h"
21 #include "simulator.h"
22 #include "simulator-impl.h"
23 #include "default-simulator-impl.h"
25 # include "realtime-simulator-impl.h"
27 #include "scheduler.h"
28 #include "map-scheduler.h"
29 #include "event-impl.h"
32 #include "ns3/string.h"
33 #include "ns3/object-factory.h"
34 #include "ns3/global-value.h"
35 #include "ns3/assert.h"
44 NS_LOG_COMPONENT_DEFINE ("Simulator");
48 GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType",
49 "The object class to use as the simulator implementation",
50 StringValue ("ns3::DefaultSimulatorImpl"),
51 MakeStringChecker ());
53 GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType",
54 "The object class to use as the scheduler implementation",
55 TypeIdValue (MapScheduler::GetTypeId ()),
56 MakeTypeIdChecker ());
62 // Note: Calls that take TimePrinter as a parameter are defined as nothing
63 // in the logging module if NS3_LOG_ENABLE is not defined.
67 TimePrinter (std::ostream &os)
69 os << Simulator::Now ().GetSeconds () << "s";
72 #endif /* NS3_LOG_ENABLE */
74 static Ptr<SimulatorImpl> *PeekImpl (void)
76 static Ptr<SimulatorImpl> impl = 0;
80 static SimulatorImpl * GetImpl (void)
82 Ptr<SimulatorImpl> &impl = *PeekImpl ();
83 /* Please, don't include any calls to logging macros in this function
84 * or pay the price, that is, stack explosions.
89 ObjectFactory factory;
92 g_simTypeImpl.GetValue (s);
93 factory.SetTypeId (s.Get ());
94 impl = factory.Create<SimulatorImpl> ();
97 ObjectFactory factory;
99 g_schedTypeImpl.GetValue (s);
100 factory.SetTypeId (s.Get ());
101 impl->SetScheduler (factory);
105 // Note: we call LogSetTimePrinter _after_ creating the implementation
106 // object because the act of creation can trigger calls to the logging
107 // framework which would call the TimePrinter function which would call
108 // Simulator::Now which would call Simulator::GetImpl, and, thus, get us
109 // in an infinite recursion until the stack explodes.
111 LogSetTimePrinter (&TimePrinter);
113 return PeekPointer (impl);
117 Simulator::Destroy (void)
119 NS_LOG_FUNCTION_NOARGS ();
121 Ptr<SimulatorImpl> &impl = *PeekImpl ();
126 /* Note: we have to call LogSetTimePrinter (0) below because if we do not do
127 * this, and restart a simulation after this call to Destroy, (which is
128 * legal), Simulator::GetImpl will trigger again an infinite recursion until
129 * the stack explodes.
131 LogSetTimePrinter (0);
137 Simulator::SetScheduler (ObjectFactory schedulerFactory)
139 NS_LOG_FUNCTION (schedulerFactory);
140 GetImpl ()->SetScheduler (schedulerFactory);
144 Simulator::IsFinished (void)
146 NS_LOG_FUNCTION_NOARGS ();
147 return GetImpl ()->IsFinished ();
151 Simulator::Next (void)
153 NS_LOG_FUNCTION_NOARGS ();
154 return GetImpl ()->Next ();
158 Simulator::Run (void)
160 NS_LOG_FUNCTION_NOARGS ();
165 Simulator::RunOneEvent (void)
167 NS_LOG_FUNCTION_NOARGS ();
168 GetImpl ()->RunOneEvent ();
172 Simulator::Stop (void)
174 NS_LOG_LOGIC ("stop");
179 Simulator::Stop (Time const &time)
181 NS_LOG_FUNCTION (time);
182 Simulator::Schedule (time, &Simulator::Stop);
186 Simulator::Now (void)
188 /* Please, don't include any calls to logging macros in this function
189 * or pay the price, that is, stack explosions.
191 return GetImpl ()->Now ();
195 Simulator::GetDelayLeft (const EventId &id)
197 NS_LOG_FUNCTION (&id);
198 return GetImpl ()->GetDelayLeft (id);
202 Simulator::Schedule (Time const &time, const Ptr<EventImpl> &ev)
204 NS_LOG_FUNCTION (time << ev);
205 return DoSchedule (time, GetPointer (ev));
209 Simulator::ScheduleNow (const Ptr<EventImpl> &ev)
211 NS_LOG_FUNCTION (ev);
212 return DoScheduleNow (GetPointer (ev));
216 Simulator::ScheduleDestroy (const Ptr<EventImpl> &ev)
218 NS_LOG_FUNCTION (ev);
219 return DoScheduleDestroy (GetPointer (ev));
222 Simulator::DoSchedule (Time const &time, EventImpl *impl)
224 return GetImpl ()->Schedule (time, impl);
227 Simulator::DoScheduleNow (EventImpl *impl)
229 return GetImpl ()->ScheduleNow (impl);
232 Simulator::DoScheduleDestroy (EventImpl *impl)
234 return GetImpl ()->ScheduleDestroy (impl);
239 Simulator::Schedule (Time const &time, void (*f) (void))
241 NS_LOG_FUNCTION (time << f);
242 return DoSchedule (time, MakeEvent (f));
246 Simulator::ScheduleNow (void (*f) (void))
249 return DoScheduleNow (MakeEvent (f));
253 Simulator::ScheduleDestroy (void (*f) (void))
256 return DoScheduleDestroy (MakeEvent (f));
260 Simulator::Remove (const EventId &ev)
262 NS_LOG_FUNCTION (&ev);
263 return GetImpl ()->Remove (ev);
267 Simulator::Cancel (const EventId &ev)
269 NS_LOG_FUNCTION (&ev);
270 return GetImpl ()->Cancel (ev);
274 Simulator::IsExpired (const EventId &id)
276 NS_LOG_FUNCTION (&id);
277 return GetImpl ()->IsExpired (id);
282 NS_LOG_FUNCTION_NOARGS ();
283 return Time (Simulator::Now ());
287 Simulator::GetMaximumSimulationTime (void)
289 NS_LOG_FUNCTION_NOARGS ();
290 return GetImpl ()->GetMaximumSimulationTime ();
294 Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
296 if (*PeekImpl () != 0)
298 NS_FATAL_ERROR ("It is not possible to set the implementation after calling any Simulator:: function. Call Simulator::SetImplementation earlier or after Simulator::Destroy.");
301 // Set the default scheduler
302 ObjectFactory factory;
304 g_schedTypeImpl.GetValue (s);
305 factory.SetTypeId (s.Get ());
306 impl->SetScheduler (factory);
308 // Note: we call LogSetTimePrinter _after_ creating the implementation
309 // object because the act of creation can trigger calls to the logging
310 // framework which would call the TimePrinter function which would call
311 // Simulator::Now which would call Simulator::GetImpl, and, thus, get us
312 // in an infinite recursion until the stack explodes.
314 LogSetTimePrinter (&TimePrinter);
317 Simulator::GetImplementation (void)
326 #include "ns3/test.h"
327 #include "list-scheduler.h"
328 #include "heap-scheduler.h"
329 #include "map-scheduler.h"
330 #include "calendar-scheduler.h"
331 #include "ns2-calendar-scheduler.h"
335 class SimulatorEventsTestCase : public TestCase
338 SimulatorEventsTestCase (ObjectFactory schedulerFactory);
339 virtual bool DoRun (void);
345 uint64_t NowUs (void);
354 ObjectFactory m_schedulerFactory;
357 SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory)
358 : TestCase ("Check that basic event handling is working with " +
359 schedulerFactory.GetTypeId ().GetName ()),
360 m_schedulerFactory (schedulerFactory)
363 SimulatorEventsTestCase::NowUs (void)
365 uint64_t ns = Now ().GetNanoSeconds ();
370 SimulatorEventsTestCase::A (int a)
376 SimulatorEventsTestCase::B (int b)
378 if (b != 2 || NowUs () != 11)
386 Simulator::Remove (m_idC);
387 Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::D, this, 4);
391 SimulatorEventsTestCase::C (int c)
397 SimulatorEventsTestCase::D (int d)
399 if (d != 4 || NowUs () != (11+10))
410 SimulatorEventsTestCase::foo0(void)
414 SimulatorEventsTestCase::destroy (void)
416 if (m_destroyId.IsExpired ())
422 SimulatorEventsTestCase::DoRun (void)
429 Simulator::SetScheduler (m_schedulerFactory);
431 EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1);
432 Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2);
433 m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3);
435 NS_TEST_EXPECT_MSG_EQ (!m_idC.IsExpired (), true, "");
436 NS_TEST_EXPECT_MSG_EQ (!a.IsExpired (), true, "");
437 Simulator::Cancel (a);
438 NS_TEST_EXPECT_MSG_EQ (a.IsExpired (), true, "");
440 NS_TEST_EXPECT_MSG_EQ (m_a, true, "Event A did not run ?");
441 NS_TEST_EXPECT_MSG_EQ (m_b, true, "Event B did not run ?");
442 NS_TEST_EXPECT_MSG_EQ (m_c, true, "Event C did not run ?");
443 NS_TEST_EXPECT_MSG_EQ (m_d, true, "Event D did not run ?");
445 EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::foo0, this);
446 EventId anotherId = anId;
447 NS_TEST_EXPECT_MSG_EQ (!(anId.IsExpired () || anotherId.IsExpired ()), true, "Event should not have expired yet.");
449 Simulator::Remove (anId);
450 NS_TEST_EXPECT_MSG_EQ (anId.IsExpired (), true, "Event was removed: it is now expired");
451 NS_TEST_EXPECT_MSG_EQ (anotherId.IsExpired (), true, "Event was removed: it is now expired");
454 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
455 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
456 m_destroyId.Cancel ();
457 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
459 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
460 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
461 Simulator::Remove (m_destroyId);
462 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
464 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
465 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
468 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
469 NS_TEST_EXPECT_MSG_EQ (!m_destroy, true, "Event should not have run");
471 Simulator::Destroy ();
472 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event should have expired now");
473 NS_TEST_EXPECT_MSG_EQ (m_destroy, true, "Event should have run");
478 class SimulatorTemplateTestCase : public TestCase
481 SimulatorTemplateTestCase ();
482 // only here for testing of Ptr<>
483 void Ref (void) const {}
484 void Unref (void) const {}
486 virtual bool DoRun (void);
490 void bar2 (int, int) {}
491 void bar3 (int, int, int) {}
492 void bar4 (int, int, int, int) {}
493 void bar5 (int, int, int, int, int) {}
495 void baz2 (int &, int &) {}
496 void baz3 (int &, int &, int &) {}
497 void baz4 (int &, int &, int &, int &) {}
498 void baz5 (int &, int &, int &, int &, int &) {}
499 void cbaz1 (const int &) {}
500 void cbaz2 (const int &, const int &) {}
501 void cbaz3 (const int &, const int &, const int &) {}
502 void cbaz4 (const int &, const int &, const int &, const int &) {}
503 void cbaz5 (const int &, const int &, const int &, const int &, const int &) {}
505 void bar0c (void) const {}
506 void bar1c (int) const {}
507 void bar2c (int, int) const {}
508 void bar3c (int, int, int) const {}
509 void bar4c (int, int, int, int) const {}
510 void bar5c (int, int, int, int, int) const {}
511 void baz1c (int &) const {}
512 void baz2c (int &, int &) const {}
513 void baz3c (int &, int &, int &) const {}
514 void baz4c (int &, int &, int &, int &) const {}
515 void baz5c (int &, int &, int &, int &, int &) const {}
516 void cbaz1c (const int &) const {}
517 void cbaz2c (const int &, const int &) const {}
518 void cbaz3c (const int &, const int &, const int &) const {}
519 void cbaz4c (const int &, const int &, const int &, const int &) const {}
520 void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {}
524 static void foo0 (void)
526 static void foo1 (int)
528 static void foo2 (int, int)
530 static void foo3 (int, int, int)
532 static void foo4 (int, int, int, int)
534 static void foo5 (int, int, int, int, int)
536 static void ber1 (int &)
538 static void ber2 (int &, int &)
540 static void ber3 (int &, int &, int &)
542 static void ber4 (int &, int &, int &, int &)
544 static void ber5 (int &, int &, int &, int &, int &)
546 static void cber1 (const int &)
548 static void cber2 (const int &, const int &)
550 static void cber3 (const int &, const int &, const int &)
552 static void cber4 (const int &, const int &, const int &, const int &)
554 static void cber5 (const int &, const int &, const int &, const int &, const int &)
557 SimulatorTemplateTestCase::SimulatorTemplateTestCase ()
558 : TestCase ("Check that all templates are instanciated correctly. This is a compilation test, it cannot fail at runtime.")
561 SimulatorTemplateTestCase::DoRun (void)
563 // Test schedule of const methods
564 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this);
565 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
566 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
567 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
568 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
569 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
570 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
571 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
572 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
573 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
574 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
575 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this);
576 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0);
577 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
578 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
579 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
580 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
581 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0);
582 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
583 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
584 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
585 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
586 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this);
587 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0);
588 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
589 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
590 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
591 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
592 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0);
593 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
594 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
595 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
596 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
597 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
598 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
599 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
600 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
601 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
602 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0);
603 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
604 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
605 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
606 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
607 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0);
608 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
609 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
610 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
611 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
613 // Test of schedule const methods with Ptr<> pointers
614 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
615 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
616 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
617 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
618 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
619 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
620 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
621 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
622 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
623 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
624 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
625 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
626 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
627 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
628 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
629 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
630 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
631 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
634 // Test schedule of raw functions
635 Simulator::Schedule (Seconds (0.0), &foo0);
636 Simulator::Schedule (Seconds (0.0), &foo1, 0);
637 Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
638 Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
639 Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
640 Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
641 Simulator::Schedule (Seconds (0.0), &cber1, 0);
642 Simulator::Schedule (Seconds (0.0), &cber2, 0, 0);
643 Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
644 Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
645 Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
646 Simulator::ScheduleNow (&foo0);
647 Simulator::ScheduleNow (&foo1, 0);
648 Simulator::ScheduleNow (&foo2, 0, 0);
649 Simulator::ScheduleNow (&foo3, 0, 0, 0);
650 Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
651 Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
652 Simulator::ScheduleNow (&cber1, 0);
653 Simulator::ScheduleNow (&cber2, 0, 0);
654 Simulator::ScheduleNow (&cber3, 0, 0, 0);
655 Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
656 Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
657 Simulator::ScheduleDestroy (&foo0);
658 Simulator::ScheduleDestroy (&foo1, 0);
659 Simulator::ScheduleDestroy (&foo2, 0, 0);
660 Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
661 Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
662 Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
663 Simulator::ScheduleDestroy (&cber1, 0);
664 Simulator::ScheduleDestroy (&cber2, 0, 0);
665 Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
666 Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
667 Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
670 // Test schedule of normal member methods
671 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this);
672 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0);
673 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
674 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
675 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
676 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
677 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
678 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
679 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
680 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
681 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
682 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this);
683 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0);
684 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0);
685 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
686 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
687 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
688 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0);
689 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
690 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
691 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
692 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
693 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this);
694 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0);
695 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0);
696 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
697 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
698 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
699 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0);
700 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
701 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
702 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
703 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
706 // test schedule of normal methods with Ptr<> pointers
707 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
708 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
709 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
710 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
711 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
712 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
713 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
714 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
715 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
716 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
717 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
718 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
719 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
720 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
721 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
722 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
723 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
724 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
727 // the code below does not compile, as expected.
728 //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
731 // This code appears to be duplicate test code.
732 Simulator::Schedule (Seconds (0.0), &ber1, 0);
733 Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
734 Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
735 Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
736 Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
737 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0);
738 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
739 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
740 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
741 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
742 Simulator::ScheduleNow (&ber1, 0);
743 Simulator::ScheduleNow (&ber2, 0, 0);
744 Simulator::ScheduleNow (&ber3, 0, 0, 0);
745 Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
746 Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
747 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0);
748 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0);
749 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
750 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
751 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
752 Simulator::ScheduleDestroy (&ber1, 0);
753 Simulator::ScheduleDestroy (&ber2, 0, 0);
754 Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
755 Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
756 Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
757 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0);
758 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0);
759 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
760 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
761 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
765 Simulator::Destroy ();
770 class SimulatorTestSuite : public TestSuite
773 SimulatorTestSuite ()
774 : TestSuite ("simulator")
776 ObjectFactory factory;
777 factory.SetTypeId (ListScheduler::GetTypeId ());
779 AddTestCase (new SimulatorEventsTestCase (factory));
780 factory.SetTypeId (MapScheduler::GetTypeId ());
781 AddTestCase (new SimulatorEventsTestCase (factory));
782 factory.SetTypeId (HeapScheduler::GetTypeId ());
783 AddTestCase (new SimulatorEventsTestCase (factory));
784 factory.SetTypeId (CalendarScheduler::GetTypeId ());
785 AddTestCase (new SimulatorEventsTestCase (factory));
786 factory.SetTypeId (Ns2CalendarScheduler::GetTypeId ());
787 AddTestCase (new SimulatorEventsTestCase (factory));
789 } g_simulatorTestSuite;