A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
23
inserted_function
(
void
)
24
{
25
NS_ASSERT
(
gFirstRun
);
26
NS_LOG_UNCOND
(
"inserted_function() called at "
<<
27
Simulator::Now
().GetSeconds () <<
" s"
);
28
}
29
30
void
31
background_function
(
void
)
32
{
33
NS_ASSERT
(
gFirstRun
);
34
NS_LOG_UNCOND
(
"background_function() called at "
<<
35
Simulator::Now
().GetSeconds () <<
" s"
);
36
}
37
38
void
39
first_function
(
void
)
40
{
41
NS_LOG_UNCOND
(
"first_function() called at "
<<
42
Simulator::Now
().GetSeconds () <<
" s"
);
43
gFirstRun
=
true
;
44
}
45
46
class
FakeNetDevice
47
{
48
public
:
49
FakeNetDevice
();
50
void
Doit3 (
void
);
51
};
52
53
FakeNetDevice::FakeNetDevice
()
54
{
55
NS_LOG_FUNCTION_NOARGS
();
56
}
57
58
void
59
FakeNetDevice::Doit3
(
void
)
60
{
61
NS_LOG_FUNCTION_NOARGS
();
62
sleep (1);
63
for
(uint32_t i = 0; i < 10000; ++i)
64
{
65
//
66
// Exercise the realtime relative now path
67
//
68
Simulator::ScheduleWithContext
(0xffffffff,
Seconds
(0.0),
MakeEvent
(&
inserted_function
));
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
//
85
Simulator::ScheduleWithContext
(0xffffffff,
Seconds
(0.0),
MakeEvent
(&
first_function
));
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
{
92
Simulator::Schedule
(
Seconds
(d), &
background_function
);
93
}
94
95
Ptr<SystemThread>
st3 = Create<SystemThread> (
96
MakeCallback
(&
FakeNetDevice::Doit3
, &fnd));
97
st3->
Start
();
98
99
Simulator::Stop
(
Seconds
(15.0));
100
Simulator::Run
();
101
st3->
Join
();
102
Simulator::Destroy
();
103
}
104
105
int
106
main
(
int
argc,
char
*argv[])
107
{
108
while
(
true
)
109
{
110
test
();
111
}
112
}
113
src
core
examples
main-test-sync.cc
Generated on Tue May 14 2013 11:08:17 for ns-3 by
1.8.1.2