ChannelModelBase.h Source File

Simu5G: ChannelModelBase.h Source File
Simu5G
ChannelModelBase.h
1//
2// Simu5G
3//
4// Copyright (C) 2012-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef STACK_PHY_CHANNELMODEL_CHANNELMODELBASE_H_
14#define STACK_PHY_CHANNELMODEL_CHANNELMODELBASE_H_
15
16#include <inet/common/ModuleRefByPar.h>
17
18#include "simu5g/common/LteCommon.h"
19#include "simu5g/common/LteControlInfo.h"
20#include "simu5g/common/carrierAggregation/ComponentCarrier.h"
21#include "simu5g/stack/phy/PhyBase.h"
22#include "simu5g/stack/phy/packet/LteAirFrame.h"
23namespace simu5g {
24
25using namespace inet;
26using namespace omnetpp;
27
28class LteAirFrame;
29class PhyBase;
30class Binder;
31
46struct LinkKey
47{
48 MacNodeId a = NODEID_NONE;
49 MacNodeId b = NODEID_NONE;
50
51 LinkKey() = default;
52 explicit LinkKey(MacNodeId node) : a(node), b(node) {}
53 LinkKey(MacNodeId x, MacNodeId y)
54 : a(num(x) <= num(y) ? x : y), b(num(x) <= num(y) ? y : x) {}
55
56 bool operator<(const LinkKey& o) const
57 {
58 return num(a) != num(o.a) ? num(a) < num(o.a) : num(b) < num(o.b);
59 }
60 bool operator==(const LinkKey& o) const { return a == o.a && b == o.b; }
61};
62
63inline std::ostream& operator<<(std::ostream& os, const LinkKey& k)
64{
65 return num(k.a) == num(k.b) ? (os << k.a) : (os << "[" << k.a << "," << k.b << "]");
66}
67
85{
86 // ---- geometry ----
87 MacNodeId txId = NODEID_NONE;
88 MacNodeId rxId = NODEID_NONE;
89 inet::Coord txCoord;
90 inet::Coord rxCoord;
91
92 // ---- channel state ----
93 // stateKey indexes the *per-link* state: losMap_, lastComputedSF_,
94 // jakesFadingMap_ and lastCorrelationPoint_.
95 LinkKey stateKey;
96
97 // stateNodeId is the *node* the state belongs to -- the UE. It selects which
98 // module owns the maps (with useUeSideMaps they are fetched from that UE's own
99 // channel model via obtainShadowingMap() / obtainUeJakesMap(), otherwise they
100 // are this module's), it indexes positionHistory_, which is genuinely a node
101 // property because it defines the node's speed, and it distinguishes
102 // background UEs.
103 MacNodeId stateNodeId = NODEID_NONE;
104
105 inet::Coord stateCoord; // position feeding computeSpeed + correlation distance
106 bool useUeSideMaps = false; // the former 'cqiDl' flag
107
108 // ---- link budget ----
109 double txAntennaGain = 0.0;
110 double rxAntennaGain = 0.0;
111 double noiseFigure = 0.0;
112 bool txIsBaseStation = false; // gates angular attenuation
113
114 // The cell this link belongs to. Only the interference computation needs it --
115 // that model is genuinely cellular-topology-aware, since it asks which cell an
116 // interferer is in. For a cellular link it is the base-station endpoint; for a
117 // UE-to-UE link it is the transmitter's serving cell.
118 MacNodeId cellId = NODEID_NONE;
119
120 // ---- tag, not a switch ----
121 Direction dir = UNKNOWN_DIRECTION;
122};
123
144class ChannelModelBase : public cSimpleModule
145{
146 protected:
147 // Reference to Binder module
148 inet::ModuleRefByPar<Binder> binder_;
149
150 // Reference to cell info module
151 inet::ModuleRefByPar<CellInfo> cellInfo_;
152
153 // Reference to the corresponding PHY layer
154 opp_component_ptr<PhyBase> phy_;
155
156 // Reference to the component carrier
157 inet::ModuleRefByPar<ComponentCarrier> componentCarrier_;
158
159 // Carrier Frequency and its base-10 logarithm
160 GHz carrierFrequency_;
161 double carrierFrequencyHz_;
162 double carrierFrequencyGHz_;
163 double log10CarrierFrequencyGHz_;
164
165 // Number of bands for this carrier
166 unsigned int numBands_ = -1;
167
168 public:
169
170 void initialize(int stage) override;
171 int numInitStages() const override { return inet::NUM_INIT_STAGES; }
172
173 /*
174 * Returns the carrier frequency
175 */
176 virtual GHz getCarrierFrequency() const { return GHz(carrierFrequencyGHz_); }
177
178 /*
179 * Returns the number of logical bands
180 */
181 virtual unsigned int getNumBands() const { return numBands_; }
182
183 /*
184 * Returns the numerology index
185 */
186 virtual unsigned int getNumerologyIndex() const { return componentCarrier_->getNumerologyIndex(); }
187
188 virtual void setPhy(PhyBase *phy) { phy_ = phy; }
189
190 /*
191 * Compute the error probability of the transmitted packet according to CQI used, TX mode, and the received power
192 * After that, it generates a random number to check if this packet will be corrupted or not
193 *
194 * @param frame pointer to the packet
195 * @param lteInfo pointer to the user control info
196 * @param rsrpVector the per-band received power captured for this frame, when the
197 * caller already has it (the D2D one-to-many capture-effect path). Empty
198 * otherwise; models that do not need it ignore it.
199 */
200 virtual bool isReceptionSuccessful(LteAirFrame *frame, UserControlInfo *lteInfo, const std::vector<double>& rsrpVector = {}) = 0;
201
202 /*
203 * Compute attenuation (path loss + optional shadowing) over a radio link.
204 *
205 * @param link the two endpoints and the channel-state key to evaluate against
206 */
207 virtual double getAttenuation(const RadioLink& link) = 0;
208 /*
209 * Compute the path-loss attenuation according to the selected scenario
210 *
211 * @param distance between UE and eNodeB
212 * @param los line-of-sight flag
213 */
214 virtual double computePathLoss(double distance, double dbp, bool los) = 0;
215 /*
216 * Compute SIR for each band for user nodeId according to multipath fading
217 *
218 * @param frame pointer to the packet
219 * @param lteInfo pointer to the user control info
220 */
221 virtual std::vector<double> getSIR(LteAirFrame *frame, UserControlInfo *lteInfo) = 0;
222 /*
223 * Compute SINR for each band for user nodeId according to path loss, shadowing (optional), and multipath fading
224 *
225 * @param frame pointer to the packet
226 * @param lteInfo pointer to the user control info
227 */
228 virtual std::vector<double> getSINR(LteAirFrame *frame, UserControlInfo *lteInfo) = 0;
229 /*
230 * Compute SINR for each band for a background UE according to path loss
231 *
232 * @param frame pointer to the packet
233 * @param lteInfo pointer to the user control info
234 */
235 virtual std::vector<double> getSINR_bgUe(LteAirFrame *frame, UserControlInfo *lteInfo) = 0;
236
237 /*
238 * Compute received power for a background UE according to path loss
239 *
240 */
241 virtual double getReceivedPower_bgUe(double txPower, inet::Coord txPos, inet::Coord rxPos, Direction dir, bool losStatus, MacNodeId bsId) = 0;
242
243 /*
244 * Compute received useful signal for each band for user nodeId according to path loss, shadowing (optional), and multipath fading
245 *
246 * @param frame pointer to the packet
247 * @param lteInfo pointer to the user control info
248 */
249 virtual std::vector<double> getRSRP(LteAirFrame *frame, UserControlInfo *lteInfo) = 0;
250
251 virtual bool isUplinkInterferenceEnabled() { return false; }
252
255 virtual bool recordsUlTransmissionMap() { return isUplinkInterferenceEnabled(); }
256};
257
258} //namespace
259
260#endif
261
Definition Binder.h:48
Definition ChannelModelBase.h:145
virtual bool recordsUlTransmissionMap()
Definition ChannelModelBase.h:255
Definition AlertReceiver.h:24
constexpr MacNodeId NODEID_NONE
MAC node ID.
Definition LteTypes.h:54
Definition ChannelModelBase.h:47