A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
propagation-cache.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012 Telum (www.telum.ru)
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Kirill Andreev <andreev@telum.ru>
18
*/
19
#ifndef PROPAGATION_CACHE_H_
20
#define PROPAGATION_CACHE_H_
21
22
#include "ns3/mobility-model.h"
23
24
#include <map>
25
26
namespace
ns3
27
{
28
/**
29
* \ingroup propagation
30
* \brief Constructs a cache of objects, where each object is responsible for a single propagation
31
* path loss calculations. Propagation path a-->b and b-->a is the same thing. Propagation path is
32
* identified by a couple of MobilityModels and a spectrum model UID
33
*/
34
template
<
class
T>
35
class
PropagationCache
36
{
37
public
:
38
PropagationCache
(){};
39
~PropagationCache
(){};
40
41
/**
42
* Get the model associated with the path
43
* \param a 1st node mobility model
44
* \param b 2nd node mobility model
45
* \param modelUid model UID
46
* \return the model
47
*/
48
Ptr<T>
GetPathData
(
Ptr<const MobilityModel>
a,
Ptr<const MobilityModel>
b,
uint32_t
modelUid)
49
{
50
PropagationPathIdentifier
key =
PropagationPathIdentifier
(a, b, modelUid);
51
auto
it =
m_pathCache
.find(key);
52
if
(it ==
m_pathCache
.end())
53
{
54
return
nullptr
;
55
}
56
return
it->second;
57
}
58
59
/**
60
* Add a model to the path
61
* \param data the model to associate to the path
62
* \param a 1st node mobility model
63
* \param b 2nd node mobility model
64
* \param modelUid model UID
65
*/
66
void
AddPathData
(
Ptr<T>
data
,
67
Ptr<const MobilityModel>
a,
68
Ptr<const MobilityModel>
b,
69
uint32_t
modelUid)
70
{
71
PropagationPathIdentifier
key =
PropagationPathIdentifier
(a, b, modelUid);
72
NS_ASSERT
(
m_pathCache
.find(key) ==
m_pathCache
.end());
73
m_pathCache
.insert(std::make_pair(key,
data
));
74
}
75
76
/**
77
* Clean the cache
78
*/
79
void
Cleanup
()
80
{
81
for
(
auto
i :
m_pathCache
)
82
{
83
i.second->Dispose();
84
}
85
m_pathCache
.clear();
86
}
87
88
private
:
89
/// Each path is identified by
90
struct
PropagationPathIdentifier
91
{
92
/**
93
* Constructor
94
* @param a 1st node mobility model
95
* @param b 2nd node mobility model
96
* @param modelUid model UID
97
*/
98
PropagationPathIdentifier
(
Ptr<const MobilityModel>
a,
99
Ptr<const MobilityModel>
b,
100
uint32_t
modelUid)
101
:
m_srcMobility
(a),
102
m_dstMobility
(b),
103
m_spectrumModelUid
(modelUid){};
104
Ptr<const MobilityModel>
m_srcMobility
;
//!< 1st node mobility model
105
Ptr<const MobilityModel>
m_dstMobility
;
//!< 2nd node mobility model
106
uint32_t
m_spectrumModelUid
;
//!< model UID
107
108
/**
109
* Less-than operator.
110
*
111
* The goal of this operator is just to provide a stable comparison
112
* to be used in containers requiring a order (of any kind).
113
*
114
* If the models are different, the comparison is based on their Uid.
115
* Otherwise, the comparison is based on the pointers of the Mobility models.
116
*
117
* \param other Right value of the operator.
118
* \returns True if the Left value is less than the Right value.
119
*/
120
bool
operator<
(
const
PropagationPathIdentifier
& other)
const
121
{
122
if
(
m_spectrumModelUid
!= other.
m_spectrumModelUid
)
123
{
124
return
m_spectrumModelUid
< other.
m_spectrumModelUid
;
125
}
126
/// Links are supposed to be symmetrical!
127
if
(std::min(
m_dstMobility
,
m_srcMobility
) !=
128
std::min(other.
m_dstMobility
, other.
m_srcMobility
))
129
{
130
return
std::min(
m_dstMobility
,
m_srcMobility
) <
131
std::min(other.
m_dstMobility
, other.
m_srcMobility
);
132
}
133
if
(std::max(
m_dstMobility
,
m_srcMobility
) !=
134
std::max(other.
m_dstMobility
, other.
m_srcMobility
))
135
{
136
return
std::max(
m_dstMobility
,
m_srcMobility
) <
137
std::max(other.
m_dstMobility
, other.
m_srcMobility
);
138
}
139
return
false
;
140
}
141
};
142
143
/// Typedef: PropagationPathIdentifier, Ptr<T>
144
typedef
std::map<PropagationPathIdentifier, Ptr<T>>
PathCache
;
145
146
private
:
147
PathCache
m_pathCache
;
//!< Path cache
148
};
149
}
// namespace ns3
150
151
#endif
// PROPAGATION_CACHE_H_
ns3::PropagationCache
Constructs a cache of objects, where each object is responsible for a single propagation path loss ca...
Definition:
propagation-cache.h:36
ns3::PropagationCache::m_pathCache
PathCache m_pathCache
Path cache.
Definition:
propagation-cache.h:147
ns3::PropagationCache::PropagationCache
PropagationCache()
Definition:
propagation-cache.h:38
ns3::PropagationCache::PathCache
std::map< PropagationPathIdentifier, Ptr< T > > PathCache
Typedef: PropagationPathIdentifier, Ptr<T>
Definition:
propagation-cache.h:144
ns3::PropagationCache::Cleanup
void Cleanup()
Clean the cache.
Definition:
propagation-cache.h:79
ns3::PropagationCache::GetPathData
Ptr< T > GetPathData(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Get the model associated with the path.
Definition:
propagation-cache.h:48
ns3::PropagationCache::~PropagationCache
~PropagationCache()
Definition:
propagation-cache.h:39
ns3::PropagationCache::AddPathData
void AddPathData(Ptr< T > data, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Add a model to the path.
Definition:
propagation-cache.h:66
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
uint32_t
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition:
assert.h:66
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
data
uint8_t data[writeSize]
Definition:
socket-bound-tcp-static-routing.cc:52
ns3::PropagationCache::PropagationPathIdentifier
Each path is identified by.
Definition:
propagation-cache.h:91
ns3::PropagationCache::PropagationPathIdentifier::PropagationPathIdentifier
PropagationPathIdentifier(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Constructor.
Definition:
propagation-cache.h:98
ns3::PropagationCache::PropagationPathIdentifier::m_srcMobility
Ptr< const MobilityModel > m_srcMobility
1st node mobility model
Definition:
propagation-cache.h:104
ns3::PropagationCache::PropagationPathIdentifier::m_spectrumModelUid
uint32_t m_spectrumModelUid
model UID
Definition:
propagation-cache.h:106
ns3::PropagationCache::PropagationPathIdentifier::m_dstMobility
Ptr< const MobilityModel > m_dstMobility
2nd node mobility model
Definition:
propagation-cache.h:105
ns3::PropagationCache::PropagationPathIdentifier::operator<
bool operator<(const PropagationPathIdentifier &other) const
Less-than operator.
Definition:
propagation-cache.h:120
src
propagation
model
propagation-cache.h
Generated on Tue May 28 2024 23:39:04 for ns-3 by
1.9.6