A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
main-test-sync.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 
3 #include "ns3/simulator.h"
4 #include "ns3/realtime-simulator-impl.h"
5 #include "ns3/nstime.h"
6 #include "ns3/log.h"
7 #include "ns3/system-thread.h"
8 #include "ns3/string.h"
9 #include "ns3/config.h"
10 #include "ns3/global-value.h"
11 #include "ns3/ptr.h"
12 
13 #include <unistd.h>
14 #include <sys/time.h>
15 
16 using namespace ns3;
17 
18 NS_LOG_COMPONENT_DEFINE ("TestSync");
19 
20 bool gFirstRun = false;
21 
22 void
24 {
26  NS_LOG_UNCOND ("inserted_function() called at " <<
27  Simulator::Now ().GetSeconds () << " s");
28 }
29 
30 void
32 {
34  NS_LOG_UNCOND ("background_function() called at " <<
35  Simulator::Now ().GetSeconds () << " s");
36 }
37 
38 void
40 {
41  NS_LOG_UNCOND ("first_function() called at " <<
42  Simulator::Now ().GetSeconds () << " s");
43  gFirstRun = true;
44 }
45 
47 {
48 public:
49  FakeNetDevice ();
50  void Doit3 (void);
51 };
52 
54 {
56 }
57 
58 void
60 {
62  sleep (1);
63  for (uint32_t i = 0; i < 10000; ++i)
64  {
65  //
66  // Exercise the realtime relative now path
67  //
69  usleep (1000);
70  }
71 }
72 
73 
74 void
75 test (void)
76 {
77  GlobalValue::Bind ("SimulatorImplementationType",
78  StringValue ("ns3::RealtimeSimulatorImpl"));
79 
80  FakeNetDevice fnd;
81 
82  //
83  // Make sure ScheduleNow works when the system isn't running
84  //
86 
87  //
88  // drive the progression of m_currentTs at a ten millisecond rate from the main thread
89  //
90  for (double d = 0.; d < 14.999; d += 0.01)
91  {
93  }
94 
95  Ptr<SystemThread> st3 = Create<SystemThread> (
97  st3->Start ();
98 
99  Simulator::Stop (Seconds (15.0));
100  Simulator::Run ();
101  st3->Join ();
103 }
104 
105 int
106 main (int argc, char *argv[])
107 {
108  while (true)
109  {
110  test ();
111  }
112 }
113