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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Kirill Andreev <andreev@telum.ru>
7
*/
8
#ifndef PROPAGATION_CACHE_H_
9
#define PROPAGATION_CACHE_H_
10
11
#include "ns3/mobility-model.h"
12
13
#include <map>
14
15
namespace
ns3
16
{
17
/**
18
* \ingroup propagation
19
* \brief Constructs a cache of objects, where each object is responsible for a single propagation
20
* path loss calculations. Propagation path a-->b and b-->a is the same thing. Propagation path is
21
* identified by a couple of MobilityModels and a spectrum model UID
22
*/
23
template
<
class
T>
24
class
PropagationCache
25
{
26
public
:
27
PropagationCache
(){};
28
~PropagationCache
(){};
29
30
/**
31
* Get the model associated with the path
32
* \param a 1st node mobility model
33
* \param b 2nd node mobility model
34
* \param modelUid model UID
35
* \return the model
36
*/
37
Ptr<T>
GetPathData
(
Ptr<const MobilityModel>
a,
Ptr<const MobilityModel>
b,
uint32_t
modelUid)
38
{
39
PropagationPathIdentifier
key =
PropagationPathIdentifier
(a, b, modelUid);
40
auto
it =
m_pathCache
.find(key);
41
if
(it ==
m_pathCache
.end())
42
{
43
return
nullptr
;
44
}
45
return
it->second;
46
}
47
48
/**
49
* Add a model to the path
50
* \param data the model to associate to the path
51
* \param a 1st node mobility model
52
* \param b 2nd node mobility model
53
* \param modelUid model UID
54
*/
55
void
AddPathData
(
Ptr<T>
data
,
56
Ptr<const MobilityModel>
a,
57
Ptr<const MobilityModel>
b,
58
uint32_t
modelUid)
59
{
60
PropagationPathIdentifier
key =
PropagationPathIdentifier
(a, b, modelUid);
61
NS_ASSERT
(
m_pathCache
.find(key) ==
m_pathCache
.end());
62
m_pathCache
.insert(std::make_pair(key,
data
));
63
}
64
65
/**
66
* Clean the cache
67
*/
68
void
Cleanup
()
69
{
70
for
(
auto
i :
m_pathCache
)
71
{
72
i.second->Dispose();
73
}
74
m_pathCache
.clear();
75
}
76
77
private
:
78
/// Each path is identified by
79
struct
PropagationPathIdentifier
80
{
81
/**
82
* Constructor
83
* @param a 1st node mobility model
84
* @param b 2nd node mobility model
85
* @param modelUid model UID
86
*/
87
PropagationPathIdentifier
(
Ptr<const MobilityModel>
a,
88
Ptr<const MobilityModel>
b,
89
uint32_t
modelUid)
90
:
m_srcMobility
(a),
91
m_dstMobility
(b),
92
m_spectrumModelUid
(modelUid){};
93
Ptr<const MobilityModel>
m_srcMobility
;
//!< 1st node mobility model
94
Ptr<const MobilityModel>
m_dstMobility
;
//!< 2nd node mobility model
95
uint32_t
m_spectrumModelUid
;
//!< model UID
96
97
/**
98
* Less-than operator.
99
*
100
* The goal of this operator is just to provide a stable comparison
101
* to be used in containers requiring a order (of any kind).
102
*
103
* If the models are different, the comparison is based on their Uid.
104
* Otherwise, the comparison is based on the pointers of the Mobility models.
105
*
106
* \param other Right value of the operator.
107
* \returns True if the Left value is less than the Right value.
108
*/
109
bool
operator<
(
const
PropagationPathIdentifier
& other)
const
110
{
111
if
(
m_spectrumModelUid
!= other.
m_spectrumModelUid
)
112
{
113
return
m_spectrumModelUid
< other.
m_spectrumModelUid
;
114
}
115
/// Links are supposed to be symmetrical!
116
if
(std::min(
m_dstMobility
,
m_srcMobility
) !=
117
std::min(other.
m_dstMobility
, other.
m_srcMobility
))
118
{
119
return
std::min(
m_dstMobility
,
m_srcMobility
) <
120
std::min(other.
m_dstMobility
, other.
m_srcMobility
);
121
}
122
if
(std::max(
m_dstMobility
,
m_srcMobility
) !=
123
std::max(other.
m_dstMobility
, other.
m_srcMobility
))
124
{
125
return
std::max(
m_dstMobility
,
m_srcMobility
) <
126
std::max(other.
m_dstMobility
, other.
m_srcMobility
);
127
}
128
return
false
;
129
}
130
};
131
132
/// Typedef: PropagationPathIdentifier, Ptr<T>
133
typedef
std::map<PropagationPathIdentifier, Ptr<T>>
PathCache
;
134
135
private
:
136
PathCache
m_pathCache
;
//!< Path cache
137
};
138
}
// namespace ns3
139
140
#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:25
ns3::PropagationCache::m_pathCache
PathCache m_pathCache
Path cache.
Definition
propagation-cache.h:136
ns3::PropagationCache::PropagationCache
PropagationCache()
Definition
propagation-cache.h:27
ns3::PropagationCache::PathCache
std::map< PropagationPathIdentifier, Ptr< T > > PathCache
Typedef: PropagationPathIdentifier, Ptr<T>
Definition
propagation-cache.h:133
ns3::PropagationCache::Cleanup
void Cleanup()
Clean the cache.
Definition
propagation-cache.h:68
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:37
ns3::PropagationCache::~PropagationCache
~PropagationCache()
Definition
propagation-cache.h:28
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:55
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
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:55
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:41
ns3::PropagationCache::PropagationPathIdentifier
Each path is identified by.
Definition
propagation-cache.h:80
ns3::PropagationCache::PropagationPathIdentifier::PropagationPathIdentifier
PropagationPathIdentifier(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Constructor.
Definition
propagation-cache.h:87
ns3::PropagationCache::PropagationPathIdentifier::m_srcMobility
Ptr< const MobilityModel > m_srcMobility
1st node mobility model
Definition
propagation-cache.h:93
ns3::PropagationCache::PropagationPathIdentifier::m_spectrumModelUid
uint32_t m_spectrumModelUid
model UID
Definition
propagation-cache.h:95
ns3::PropagationCache::PropagationPathIdentifier::m_dstMobility
Ptr< const MobilityModel > m_dstMobility
2nd node mobility model
Definition
propagation-cache.h:94
ns3::PropagationCache::PropagationPathIdentifier::operator<
bool operator<(const PropagationPathIdentifier &other) const
Less-than operator.
Definition
propagation-cache.h:109
src
propagation
model
propagation-cache.h
Generated on Fri Nov 8 2024 13:59:05 for ns-3 by
1.11.0