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
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
ns3::StringValue
hold variables of type string
Definition:
string.h:19
main
int main(int argc, char *argv[])
Definition:
main-test-sync.cc:106
ns3::SystemThread::Start
void Start(void)
Start a thread of execution, running the provided callback.
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::Simulator::Run
static void Run(void)
Definition:
simulator.cc:157
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Definition:
log.h:275
ns3::Simulator::Schedule
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition:
simulator.h:824
FakeNetDevice::FakeNetDevice
FakeNetDevice()
Definition:
main-test-sync.cc:53
ns3::MakeCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition:
callback.h:1238
ns3::GlobalValue::Bind
static void Bind(std::string name, const AttributeValue &value)
Definition:
global-value.cc:149
ns3::Simulator::ScheduleWithContext
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Definition:
simulator.h:904
ns3::Simulator::Destroy
static void Destroy(void)
Definition:
simulator.cc:121
first_function
void first_function(void)
Definition:
main-test-sync.cc:39
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Definition:
log.h:343
ns3::Simulator::Now
static Time Now(void)
Definition:
simulator.cc:180
FakeNetDevice::Doit3
void Doit3(void)
Definition:
main-test-sync.cc:59
ns3::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
background_function
void background_function(void)
Definition:
main-test-sync.cc:31
ns3::Simulator::Stop
static void Stop(void)
Definition:
simulator.cc:165
gFirstRun
bool gFirstRun
Definition:
main-test-sync.cc:20
ns3::SystemThread::Join
void Join(void)
Suspend the caller until the thread of execution, running the provided callback, finishes.
ns3::MakeEvent
EventImpl * MakeEvent(void(*f)(void))
Definition:
make-event.cc:8
FakeNetDevice
Definition:
main-test-sync.cc:46
inserted_function
void inserted_function(void)
Definition:
main-test-sync.cc:23
test
void test(void)
Definition:
main-test-sync.cc:75
src
core
examples
main-test-sync.cc
Generated on Sun Apr 20 2014 11:14:46 for ns-3 by
1.8.6