src/simulator/simulator.cc
author Guillaume Seguin <guillaume@segu.in>
Thu Nov 12 13:19:35 2009 +0100 (2009-11-12)
changeset 5507 915abd2b907b
parent 5493 8ffa53e9a701
child 5521 37c6c83d4252
permissions -rw-r--r--
Simulator::SetScheduler now takes an ObjectFactory
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2005,2006 INRIA
     4  *
     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;
     8  *
     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.
    13  *
    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
    17  *
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #include "ns3/core-config.h"
    21 #include "simulator.h"
    22 #include "simulator-impl.h"
    23 #include "default-simulator-impl.h"
    24 #ifdef HAVE_PTHREAD_H
    25 # include "realtime-simulator-impl.h"
    26 #endif
    27 #include "scheduler.h"
    28 #include "map-scheduler.h"
    29 #include "event-impl.h"
    30 
    31 #include "ns3/ptr.h"
    32 #include "ns3/string.h"
    33 #include "ns3/object-factory.h"
    34 #include "ns3/global-value.h"
    35 #include "ns3/assert.h"
    36 #include "ns3/log.h"
    37 
    38 #include <math.h>
    39 #include <fstream>
    40 #include <list>
    41 #include <vector>
    42 #include <iostream>
    43 
    44 NS_LOG_COMPONENT_DEFINE ("Simulator");
    45 
    46 namespace ns3 {
    47 
    48 GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType", 
    49   "The object class to use as the simulator implementation",
    50   StringValue ("ns3::DefaultSimulatorImpl"),
    51   MakeStringChecker ());
    52 
    53 GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", 
    54   "The object class to use as the scheduler implementation",
    55   TypeIdValue (MapScheduler::GetTypeId ()),
    56   MakeTypeIdChecker ());
    57 
    58 
    59 #ifdef NS3_LOG_ENABLE
    60 
    61 //
    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.
    64 // 
    65 
    66 static void
    67 TimePrinter (std::ostream &os)
    68 {
    69   os << Simulator::Now ().GetSeconds () << "s";
    70 }
    71 
    72 #endif /* NS3_LOG_ENABLE */
    73 
    74 static Ptr<SimulatorImpl> *PeekImpl (void)
    75 {
    76   static Ptr<SimulatorImpl> impl = 0;
    77   return &impl;
    78 }
    79 
    80 static SimulatorImpl * GetImpl (void)
    81 {
    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.
    85    */
    86   if (impl == 0) 
    87     {
    88       {
    89         ObjectFactory factory;
    90         StringValue s;
    91         
    92         g_simTypeImpl.GetValue (s);
    93         factory.SetTypeId (s.Get ());
    94         impl = factory.Create<SimulatorImpl> ();
    95       }
    96       {
    97         ObjectFactory factory;
    98         StringValue s;
    99         g_schedTypeImpl.GetValue (s);
   100         factory.SetTypeId (s.Get ());
   101         impl->SetScheduler (factory);
   102       }
   103 
   104 //
   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.
   110 //
   111       LogSetTimePrinter (&TimePrinter);
   112     }
   113   return PeekPointer (impl);
   114 }
   115 
   116 void
   117 Simulator::Destroy (void)
   118 {
   119   NS_LOG_FUNCTION_NOARGS ();
   120 
   121   Ptr<SimulatorImpl> &impl = *PeekImpl (); 
   122   if (impl == 0)
   123     {
   124       return;
   125     }
   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.
   130    */
   131   LogSetTimePrinter (0);
   132   impl->Destroy ();
   133   impl = 0;
   134 }
   135 
   136 void
   137 Simulator::SetScheduler (ObjectFactory schedulerFactory)
   138 {
   139   NS_LOG_FUNCTION (schedulerFactory);
   140   GetImpl ()->SetScheduler (schedulerFactory);
   141 }
   142 
   143 bool 
   144 Simulator::IsFinished (void)
   145 {
   146   NS_LOG_FUNCTION_NOARGS ();
   147   return GetImpl ()->IsFinished ();
   148 }
   149 
   150 Time
   151 Simulator::Next (void)
   152 {
   153   NS_LOG_FUNCTION_NOARGS ();
   154   return GetImpl ()->Next ();
   155 }
   156 
   157 void 
   158 Simulator::Run (void)
   159 {
   160   NS_LOG_FUNCTION_NOARGS ();
   161   GetImpl ()->Run ();
   162 }
   163 
   164 void 
   165 Simulator::RunOneEvent (void)
   166 {
   167   NS_LOG_FUNCTION_NOARGS ();
   168   GetImpl ()->RunOneEvent ();
   169 }
   170 
   171 void 
   172 Simulator::Stop (void)
   173 {
   174   NS_LOG_LOGIC ("stop");
   175   GetImpl ()->Stop ();
   176 }
   177 
   178 void 
   179 Simulator::Stop (Time const &time)
   180 {
   181   NS_LOG_FUNCTION (time);
   182   Simulator::Schedule (time, &Simulator::Stop);
   183 }
   184 
   185 Time
   186 Simulator::Now (void)
   187 {
   188   /* Please, don't include any calls to logging macros in this function
   189    * or pay the price, that is, stack explosions.
   190    */
   191   return GetImpl ()->Now ();
   192 }
   193 
   194 Time
   195 Simulator::GetDelayLeft (const EventId &id)
   196 {
   197   NS_LOG_FUNCTION (&id);
   198   return GetImpl ()->GetDelayLeft (id);
   199 }
   200 
   201 EventId
   202 Simulator::Schedule (Time const &time, const Ptr<EventImpl> &ev)
   203 {
   204   NS_LOG_FUNCTION (time << ev);
   205   return DoSchedule (time, GetPointer (ev));
   206 }
   207 
   208 EventId
   209 Simulator::ScheduleNow (const Ptr<EventImpl> &ev)
   210 {
   211   NS_LOG_FUNCTION (ev);
   212   return DoScheduleNow (GetPointer (ev));
   213 }
   214 
   215 EventId
   216 Simulator::ScheduleDestroy (const Ptr<EventImpl> &ev)
   217 {
   218   NS_LOG_FUNCTION (ev);
   219   return DoScheduleDestroy (GetPointer (ev));
   220 }
   221 EventId 
   222 Simulator::DoSchedule (Time const &time, EventImpl *impl)
   223 {
   224   return GetImpl ()->Schedule (time, impl);
   225 }
   226 EventId 
   227 Simulator::DoScheduleNow (EventImpl *impl)
   228 {
   229   return GetImpl ()->ScheduleNow (impl);
   230 }
   231 EventId 
   232 Simulator::DoScheduleDestroy (EventImpl *impl)
   233 {
   234   return GetImpl ()->ScheduleDestroy (impl);
   235 }
   236 
   237 
   238 EventId
   239 Simulator::Schedule (Time const &time, void (*f) (void))
   240 {
   241   NS_LOG_FUNCTION (time << f);
   242   return DoSchedule (time, MakeEvent (f));
   243 }
   244 
   245 EventId
   246 Simulator::ScheduleNow (void (*f) (void))
   247 {
   248   NS_LOG_FUNCTION (f);
   249   return DoScheduleNow (MakeEvent (f));
   250 }
   251 
   252 EventId
   253 Simulator::ScheduleDestroy (void (*f) (void))
   254 {
   255   NS_LOG_FUNCTION (f);
   256   return DoScheduleDestroy (MakeEvent (f));
   257 }
   258 
   259 void
   260 Simulator::Remove (const EventId &ev)
   261 {
   262   NS_LOG_FUNCTION (&ev);
   263   return GetImpl ()->Remove (ev);
   264 }
   265 
   266 void
   267 Simulator::Cancel (const EventId &ev)
   268 {
   269   NS_LOG_FUNCTION (&ev);
   270   return GetImpl ()->Cancel (ev);
   271 }
   272 
   273 bool 
   274 Simulator::IsExpired (const EventId &id)
   275 {
   276   NS_LOG_FUNCTION (&id);
   277   return GetImpl ()->IsExpired (id);
   278 }
   279 
   280 Time Now (void)
   281 {
   282   NS_LOG_FUNCTION_NOARGS ();
   283   return Time (Simulator::Now ());
   284 }
   285 
   286 Time 
   287 Simulator::GetMaximumSimulationTime (void)
   288 {
   289   NS_LOG_FUNCTION_NOARGS ();
   290   return GetImpl ()->GetMaximumSimulationTime ();
   291 }
   292 
   293 void
   294 Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
   295 {
   296   if (*PeekImpl () != 0)
   297     {
   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.");
   299     }
   300   *PeekImpl () = impl;
   301   // Set the default scheduler
   302   ObjectFactory factory;
   303   StringValue s;
   304   g_schedTypeImpl.GetValue (s);
   305   factory.SetTypeId (s.Get ());
   306   impl->SetScheduler (factory);
   307 //
   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.
   313 //
   314   LogSetTimePrinter (&TimePrinter);
   315 }
   316 Ptr<SimulatorImpl>
   317 Simulator::GetImplementation (void)
   318 {
   319   return GetImpl ();
   320 }
   321 
   322 
   323 
   324 } // namespace ns3
   325 
   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"
   332 
   333 namespace ns3 {
   334 
   335 class SimulatorEventsTestCase : public TestCase
   336 {
   337 public:
   338   SimulatorEventsTestCase (ObjectFactory schedulerFactory);
   339   virtual bool DoRun (void);
   340   void A (int a);
   341   void B (int b);
   342   void C (int c);
   343   void D (int d);
   344   void foo0 (void);
   345   uint64_t NowUs (void);
   346   void destroy(void);
   347   bool m_b;
   348   bool m_a;
   349   bool m_c;
   350   bool m_d;
   351   EventId m_idC;
   352   bool m_destroy;
   353   EventId m_destroyId;
   354   ObjectFactory m_schedulerFactory;
   355 };
   356 
   357 SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory)
   358   : TestCase ("Check that basic event handling is working with " + 
   359               schedulerFactory.GetTypeId ().GetName ()),
   360     m_schedulerFactory (schedulerFactory)
   361 {}
   362 uint64_t
   363 SimulatorEventsTestCase::NowUs (void)
   364 {
   365   uint64_t ns = Now ().GetNanoSeconds ();
   366   return ns / 1000;
   367 }  
   368 
   369 void
   370 SimulatorEventsTestCase::A (int a)
   371 {
   372   m_a = false;
   373 }
   374 
   375 void
   376 SimulatorEventsTestCase::B (int b)
   377 {
   378   if (b != 2 || NowUs () != 11) 
   379     {
   380       m_b = false;
   381     } 
   382   else 
   383     {
   384       m_b = true;
   385     }
   386   Simulator::Remove (m_idC);
   387   Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::D, this, 4);
   388 }
   389 
   390 void
   391 SimulatorEventsTestCase::C (int c)
   392 {
   393   m_c = false;
   394 }
   395 
   396 void
   397 SimulatorEventsTestCase::D (int d)
   398 {
   399   if (d != 4 || NowUs () != (11+10)) 
   400     {
   401       m_d = false;
   402     } 
   403   else 
   404     {
   405       m_d = true;
   406     }
   407 }
   408 
   409 void
   410 SimulatorEventsTestCase::foo0(void)
   411 {}
   412 
   413 void
   414 SimulatorEventsTestCase::destroy (void)
   415 {
   416   if (m_destroyId.IsExpired ())
   417     {
   418       m_destroy = true; 
   419     }
   420 }
   421 bool 
   422 SimulatorEventsTestCase::DoRun (void)
   423 {
   424   m_a = true;
   425   m_b = false;
   426   m_c = true;
   427   m_d = false;
   428 
   429   Simulator::SetScheduler (m_schedulerFactory);
   430 
   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);
   434 
   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, "");
   439   Simulator::Run ();
   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 ?");
   444 
   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.");
   448 
   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");
   452 
   453   m_destroy = false;
   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");
   458 
   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");
   463 
   464   m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
   465   NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
   466 
   467   Simulator::Run ();
   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");
   470 
   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");
   474 
   475   return false;
   476 }
   477 
   478 class SimulatorTemplateTestCase : public TestCase
   479 {
   480 public:
   481   SimulatorTemplateTestCase ();
   482   // only here for testing of Ptr<>
   483   void Ref (void) const {}
   484   void Unref (void) const {}
   485 private:
   486   virtual bool DoRun (void);
   487 
   488   void bar0 (void) {}
   489   void bar1 (int) {}
   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) {}
   494   void baz1 (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 &) {}
   504 
   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 {}
   521 
   522 };
   523 
   524 static void foo0 (void)
   525 {}
   526 static void foo1 (int)
   527 {}
   528 static void foo2 (int, int)
   529 {}
   530 static void foo3 (int, int, int)
   531 {}
   532 static void foo4 (int, int, int, int)
   533 {}
   534 static void foo5 (int, int, int, int, int)
   535 {}
   536 static void ber1 (int &)
   537 {}
   538 static void ber2 (int &, int &)
   539 {}
   540 static void ber3 (int &, int &, int &)
   541 {}
   542 static void ber4 (int &, int &, int &, int &)
   543 {}
   544 static void ber5 (int &, int &, int &, int &, int &)
   545 {}
   546 static void cber1 (const int &)
   547 {}
   548 static void cber2 (const int &, const int &)
   549 {}
   550 static void cber3 (const int &, const int &, const int &)
   551 {}
   552 static void cber4 (const int &, const int &, const int &, const int &)
   553 {}
   554 static void cber5 (const int &, const int &, const int &, const int &, const int &)
   555 {}
   556 
   557 SimulatorTemplateTestCase::SimulatorTemplateTestCase ()
   558   : TestCase ("Check that all templates are instanciated correctly. This is a compilation test, it cannot fail at runtime.")
   559 {}
   560 bool 
   561 SimulatorTemplateTestCase::DoRun (void)
   562 {
   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);
   612 
   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);
   632 
   633 
   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);
   668 
   669 
   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);
   704 
   705 
   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);
   725 
   726 
   727   // the code below does not compile, as expected.
   728   //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
   729 
   730 
   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);
   762 
   763 
   764   Simulator::Run ();
   765   Simulator::Destroy ();
   766 
   767   return false;
   768 }
   769 
   770 class SimulatorTestSuite : public TestSuite
   771 {
   772 public:
   773   SimulatorTestSuite ()
   774     : TestSuite ("simulator")
   775   {
   776     ObjectFactory factory;
   777     factory.SetTypeId (ListScheduler::GetTypeId ());
   778 
   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));
   788   }
   789 } g_simulatorTestSuite;
   790 
   791 } // namespace ns3