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
synchronizer.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 University of Washington
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
19
#include "
synchronizer.h
"
20
#include "
log.h
"
21
22
NS_LOG_COMPONENT_DEFINE
(
"Synchronizer"
);
23
24
namespace
ns3 {
25
26
NS_OBJECT_ENSURE_REGISTERED
(Synchronizer);
27
28
TypeId
29
Synchronizer::GetTypeId
(
void
)
30
{
31
static
TypeId
tid =
TypeId
(
"ns3::Synchronizer"
)
32
.
SetParent
<
Object
> ()
33
;
34
return
tid;
35
}
36
37
Synchronizer::Synchronizer
()
38
: m_realtimeOriginNano (0), m_simOriginNano (0)
39
{
40
NS_LOG_FUNCTION
(
this
);
41
}
42
43
Synchronizer::~Synchronizer
()
44
{
45
NS_LOG_FUNCTION
(
this
);
46
}
47
48
bool
49
Synchronizer::Realtime
(
void
)
50
{
51
NS_LOG_FUNCTION
(
this
);
52
return
DoRealtime
();
53
}
54
55
uint64_t
56
Synchronizer::GetCurrentRealtime
(
void
)
57
{
58
NS_LOG_FUNCTION
(
this
);
59
return
NanosecondToTimeStep
(
DoGetCurrentRealtime
());
60
}
61
62
void
63
Synchronizer::SetOrigin
(uint64_t ts)
64
{
65
NS_LOG_FUNCTION
(
this
<< ts);
66
m_simOriginNano
=
TimeStepToNanosecond
(ts);
67
DoSetOrigin
(
m_simOriginNano
);
68
}
69
70
uint64_t
71
Synchronizer::GetOrigin
(
void
)
72
{
73
NS_LOG_FUNCTION
(
this
);
74
return
NanosecondToTimeStep
(
m_simOriginNano
);
75
}
76
77
int64_t
78
Synchronizer::GetDrift
(uint64_t ts)
79
{
80
NS_LOG_FUNCTION
(
this
<< ts);
81
int64_t tDrift =
DoGetDrift
(
TimeStepToNanosecond
(ts));
82
83
if
(tDrift < 0)
84
{
85
return
-
NanosecondToTimeStep
(-tDrift);
86
}
else
{
87
return
NanosecondToTimeStep
(tDrift);
88
}
89
}
90
91
bool
92
Synchronizer::Synchronize
(uint64_t tsCurrent, uint64_t tsDelay)
93
{
94
NS_LOG_FUNCTION
(
this
<< tsCurrent << tsDelay);
95
return
DoSynchronize
(
TimeStepToNanosecond
(tsCurrent),
96
TimeStepToNanosecond
(tsDelay));
97
}
98
99
void
100
Synchronizer::Signal
(
void
)
101
{
102
NS_LOG_FUNCTION
(
this
);
103
DoSignal
();
104
}
105
106
void
107
Synchronizer::SetCondition
(
bool
cond)
108
{
109
NS_LOG_FUNCTION
(
this
<< cond);
110
DoSetCondition
(cond);
111
}
112
113
void
114
Synchronizer::EventStart
(
void
)
115
{
116
NS_LOG_FUNCTION
(
this
);
117
DoEventStart
();
118
}
119
120
uint64_t
121
Synchronizer::EventEnd
(
void
)
122
{
123
NS_LOG_FUNCTION
(
this
);
124
return
NanosecondToTimeStep
(
DoEventEnd
());
125
}
126
127
uint64_t
128
Synchronizer::TimeStepToNanosecond
(uint64_t ts)
129
{
130
NS_LOG_FUNCTION
(
this
<< ts);
131
return
TimeStep
(ts).
GetNanoSeconds
();
132
}
133
134
uint64_t
135
Synchronizer::NanosecondToTimeStep
(uint64_t ns)
136
{
137
NS_LOG_FUNCTION
(
this
<< ns);
138
return
NanoSeconds
(ns).
GetTimeStep
();
139
}
140
141
}
// namespace ns3
142
143
src
core
model
synchronizer.cc
Generated on Tue May 14 2013 11:08:18 for ns-3 by
1.8.1.2