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
21
namespace
ns3 {
22
23
NS_OBJECT_ENSURE_REGISTERED
(Synchronizer);
24
25
TypeId
26
Synchronizer::GetTypeId
(
void
)
27
{
28
static
TypeId
tid =
TypeId
(
"ns3::Synchronizer"
)
29
.
SetParent
<
Object
> ()
30
;
31
return
tid;
32
}
33
34
Synchronizer::Synchronizer
()
35
: m_realtimeOriginNano (0), m_simOriginNano (0)
36
{
37
}
38
39
Synchronizer::~Synchronizer
()
40
{
41
}
42
43
bool
44
Synchronizer::Realtime
(
void
)
45
{
46
return
DoRealtime
();
47
}
48
49
uint64_t
50
Synchronizer::GetCurrentRealtime
(
void
)
51
{
52
return
NanosecondToTimeStep
(
DoGetCurrentRealtime
());
53
}
54
55
void
56
Synchronizer::SetOrigin
(uint64_t ts)
57
{
58
m_simOriginNano
=
TimeStepToNanosecond
(ts);
59
DoSetOrigin
(
m_simOriginNano
);
60
}
61
62
uint64_t
63
Synchronizer::GetOrigin
(
void
)
64
{
65
return
NanosecondToTimeStep
(
m_simOriginNano
);
66
}
67
68
int64_t
69
Synchronizer::GetDrift
(uint64_t ts)
70
{
71
int64_t tDrift =
DoGetDrift
(
TimeStepToNanosecond
(ts));
72
73
if
(tDrift < 0)
74
{
75
return
-
NanosecondToTimeStep
(-tDrift);
76
}
else
{
77
return
NanosecondToTimeStep
(tDrift);
78
}
79
}
80
81
bool
82
Synchronizer::Synchronize
(uint64_t tsCurrent, uint64_t tsDelay)
83
{
84
return
DoSynchronize
(
TimeStepToNanosecond
(tsCurrent),
85
TimeStepToNanosecond
(tsDelay));
86
}
87
88
void
89
Synchronizer::Signal
(
void
)
90
{
91
DoSignal
();
92
}
93
94
void
95
Synchronizer::SetCondition
(
bool
cond)
96
{
97
DoSetCondition
(cond);
98
}
99
100
void
101
Synchronizer::EventStart
(
void
)
102
{
103
DoEventStart
();
104
}
105
106
uint64_t
107
Synchronizer::EventEnd
(
void
)
108
{
109
return
NanosecondToTimeStep
(
DoEventEnd
());
110
}
111
112
uint64_t
113
Synchronizer::TimeStepToNanosecond
(uint64_t ts)
114
{
115
return
TimeStep
(ts).
GetNanoSeconds
();
116
}
117
118
uint64_t
119
Synchronizer::NanosecondToTimeStep
(uint64_t ns)
120
{
121
return
NanoSeconds
(ns).
GetTimeStep
();
122
}
123
124
}
// namespace ns3
125
126
src
core
model
synchronizer.cc
Generated on Tue Oct 9 2012 16:45:35 for ns-3 by
1.8.1.2