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
{
29
}
30
31
~PropagationCache
()
32
{
33
}
34
35
/**
36
* Get the model associated with the path
37
* @param a 1st node mobility model
38
* @param b 2nd node mobility model
39
* @param modelUid model UID
40
* @return the model
41
*/
42
Ptr<T>
GetPathData
(
Ptr<const MobilityModel>
a,
Ptr<const MobilityModel>
b,
uint32_t
modelUid)
43
{
44
PropagationPathIdentifier
key =
PropagationPathIdentifier
(a, b, modelUid);
45
auto
it =
m_pathCache
.find(key);
46
if
(it ==
m_pathCache
.end())
47
{
48
return
nullptr
;
49
}
50
return
it->second;
51
}
52
53
/**
54
* Add a model to the path
55
* @param data the model to associate to the path
56
* @param a 1st node mobility model
57
* @param b 2nd node mobility model
58
* @param modelUid model UID
59
*/
60
void
AddPathData
(
Ptr<T>
data
,
61
Ptr<const MobilityModel>
a,
62
Ptr<const MobilityModel>
b,
63
uint32_t
modelUid)
64
{
65
PropagationPathIdentifier
key =
PropagationPathIdentifier
(a, b, modelUid);
66
NS_ASSERT
(
m_pathCache
.find(key) ==
m_pathCache
.end());
67
m_pathCache
.insert(std::make_pair(key,
data
));
68
}
69
70
/**
71
* Clean the cache
72
*/
73
void
Cleanup
()
74
{
75
for
(
auto
i :
m_pathCache
)
76
{
77
i.second->Dispose();
78
}
79
m_pathCache
.clear();
80
}
81
82
private
:
83
/// Each path is identified by
84
struct
PropagationPathIdentifier
85
{
86
/**
87
* Constructor
88
* @param a 1st node mobility model
89
* @param b 2nd node mobility model
90
* @param modelUid model UID
91
*/
92
PropagationPathIdentifier
(
Ptr<const MobilityModel>
a,
93
Ptr<const MobilityModel>
b,
94
uint32_t
modelUid)
95
:
m_srcMobility
(a),
96
m_dstMobility
(b),
97
m_spectrumModelUid
(modelUid)
98
{
99
}
100
101
Ptr<const MobilityModel>
m_srcMobility
;
//!< 1st node mobility model
102
Ptr<const MobilityModel>
m_dstMobility
;
//!< 2nd node mobility model
103
uint32_t
m_spectrumModelUid
;
//!< model UID
104
105
/**
106
* Less-than operator.
107
*
108
* The goal of this operator is just to provide a stable comparison
109
* to be used in containers requiring a order (of any kind).
110
*
111
* If the models are different, the comparison is based on their Uid.
112
* Otherwise, the comparison is based on the pointers of the Mobility models.
113
*
114
* @param other Right value of the operator.
115
* @returns True if the Left value is less than the Right value.
116
*/
117
bool
operator<
(
const
PropagationPathIdentifier
& other)
const
118
{
119
if
(
m_spectrumModelUid
!= other.
m_spectrumModelUid
)
120
{
121
return
m_spectrumModelUid
< other.
m_spectrumModelUid
;
122
}
123
/// Links are supposed to be symmetrical!
124
if
(std::min(
m_dstMobility
,
m_srcMobility
) !=
125
std::min(other.
m_dstMobility
, other.
m_srcMobility
))
126
{
127
return
std::min(
m_dstMobility
,
m_srcMobility
) <
128
std::min(other.
m_dstMobility
, other.
m_srcMobility
);
129
}
130
if
(std::max(
m_dstMobility
,
m_srcMobility
) !=
131
std::max(other.
m_dstMobility
, other.
m_srcMobility
))
132
{
133
return
std::max(
m_dstMobility
,
m_srcMobility
) <
134
std::max(other.
m_dstMobility
, other.
m_srcMobility
);
135
}
136
return
false
;
137
}
138
};
139
140
/// Typedef: PropagationPathIdentifier, Ptr<T>
141
typedef
std::map<PropagationPathIdentifier, Ptr<T>>
PathCache
;
142
143
private
:
144
PathCache
m_pathCache
;
//!< Path cache
145
};
146
}
// namespace ns3
147
148
#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:144
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:141
ns3::PropagationCache::Cleanup
void Cleanup()
Clean the cache.
Definition
propagation-cache.h:73
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:42
ns3::PropagationCache::~PropagationCache
~PropagationCache()
Definition
propagation-cache.h:31
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:60
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:85
ns3::PropagationCache::PropagationPathIdentifier::PropagationPathIdentifier
PropagationPathIdentifier(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Constructor.
Definition
propagation-cache.h:92
ns3::PropagationCache::PropagationPathIdentifier::m_srcMobility
Ptr< const MobilityModel > m_srcMobility
1st node mobility model
Definition
propagation-cache.h:101
ns3::PropagationCache::PropagationPathIdentifier::m_spectrumModelUid
uint32_t m_spectrumModelUid
model UID
Definition
propagation-cache.h:103
ns3::PropagationCache::PropagationPathIdentifier::m_dstMobility
Ptr< const MobilityModel > m_dstMobility
2nd node mobility model
Definition
propagation-cache.h:102
ns3::PropagationCache::PropagationPathIdentifier::operator<
bool operator<(const PropagationPathIdentifier &other) const
Less-than operator.
Definition
propagation-cache.h:117
src
propagation
model
propagation-cache.h
Generated on Tue Dec 3 2024 18:20:52 for ns-3 by
1.11.0