Skip to content

Commit 2741de2

Browse files
committed
EndDeviceLoraPhy: Simulate channel bandwidth mismatch
- `LoraPhy`: - Change API of `StartReceive()` to also take the channel bandwidth of the incoming packet as parameter - `LoraChannel`: - Keep info of the bandwidth of a transmission and pass it on to PHYs via the new bandwidth parameter of the `StartReceive()` function - `EndDeviceLoraPhy`: - Add getter and setter for channel bandwidth to `EndDeviceLoraPhy` and initialize `EndDeviceLoraPhy` with a default bandwidth of 125 kHz. - Add `"LostPacketBecauseWrongBandwidth"` trace source to `EndDeviceLoraPhy` - `SimpleEndDeviceLoraPhy`: - Simulate loss of packet when it was received on the same frequency but on a different channel bandwidth than tuned in and call the new trace source on loss - Reduce code duplication by factoring out the retrieval of the node ID from the trac handlers.
1 parent 431481e commit 2741de2

11 files changed

Lines changed: 147 additions & 34 deletions

model/end-device-lora-phy.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ EndDeviceLoraPhy::GetTypeId()
4545
"the end device was listening on a different frequency",
4646
MakeTraceSourceAccessor(&EndDeviceLoraPhy::m_wrongFrequency),
4747
"ns3::Packet::TracedCallback")
48+
.AddTraceSource("LostPacketBecauseWrongBandwidth",
49+
"Trace source indicating a packet could not "
50+
"be correctly decoded because the end device was "
51+
"listening on a different frequency",
52+
MakeTraceSourceAccessor(&EndDeviceLoraPhy::m_wrongBandwidth),
53+
"ns3::Packet::TracedCallback")
4854
.AddTraceSource("LostPacketBecauseWrongSpreadingFactor",
4955
"Trace source indicating a packet "
5056
"could not be correctly decoded because"
@@ -63,6 +69,7 @@ EndDeviceLoraPhy::GetTypeId()
6369
EndDeviceLoraPhy::EndDeviceLoraPhy()
6470
: m_state(State::SLEEP),
6571
m_frequencyHz(868100000),
72+
m_bandwidthHz(125000),
6673
m_sf(7)
6774
{
6875
}
@@ -100,12 +107,30 @@ EndDeviceLoraPhy::IsOnFrequency(uint32_t frequencyHz)
100107
return m_frequencyHz == frequencyHz;
101108
}
102109

110+
bool
111+
EndDeviceLoraPhy::IsOnBandwidth(uint32_t bandwidthHz) const
112+
{
113+
return m_bandwidthHz == bandwidthHz;
114+
}
115+
103116
void
104117
EndDeviceLoraPhy::SetFrequency(uint32_t frequencyHz)
105118
{
106119
m_frequencyHz = frequencyHz;
107120
}
108121

122+
void
123+
EndDeviceLoraPhy::SetBandwidth(uint32_t bandwidthHz)
124+
{
125+
m_bandwidthHz = bandwidthHz;
126+
}
127+
128+
uint32_t
129+
EndDeviceLoraPhy::GetBandwidth() const
130+
{
131+
return m_bandwidthHz;
132+
}
133+
109134
void
110135
EndDeviceLoraPhy::TxFinished(Ptr<const Packet> packet)
111136
{

model/end-device-lora-phy.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ class EndDeviceLoraPhy : public LoraPhy
147147
double rxPowerDbm,
148148
uint8_t sf,
149149
Time duration,
150-
uint32_t frequencyHz) override = 0;
150+
uint32_t frequencyHz,
151+
uint32_t bandwidthHz) override = 0;
151152

152153
// Implementation of LoraPhy's pure virtual functions
153154
void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override = 0;
@@ -161,6 +162,15 @@ class EndDeviceLoraPhy : public LoraPhy
161162
// Implementation of LoraPhy's pure virtual functions
162163
bool IsOnFrequency(uint32_t frequencyHz) override;
163164

165+
/**
166+
* Checks whether the PHY is tuned in the given bandwidth>
167+
*
168+
* @param bandwidthHz The bandwidth to check
169+
* @retval true If this PHY is able to lock on the given bandwidth
170+
* @retval false If the PHY is **NOT** able to lock on the given bandwidth
171+
*/
172+
bool IsOnBandwidth(uint32_t bandwidthHz) const;
173+
164174
// Implementation of LoraPhy's pure virtual functions
165175
bool IsTransmitting() override;
166176

@@ -174,6 +184,24 @@ class EndDeviceLoraPhy : public LoraPhy
174184
*/
175185
void SetFrequency(uint32_t frequencyHz);
176186

187+
/**
188+
* Set the channel bandwidth this end device will listen on.
189+
*
190+
* Should a packet be transmitted using a different bandwidth than this
191+
* EndDeviceLoraPhy is listening on, the packet will be discarded even if
192+
* the frequency matches.
193+
*
194+
* @param bandwidthHz The bandwidth [Hz] to listen to.
195+
*/
196+
void SetBandwidth(uint32_t bandwidthHz);
197+
198+
/**
199+
* Get the channel bandwidth this end device will listen on.
200+
*
201+
* @return The bandwidth [Hz] the PHY is listening to.
202+
*/
203+
uint32_t GetBandwidth() const;
204+
177205
/**
178206
* Set the Spreading Factor this end device will listen for.
179207
*
@@ -259,13 +287,22 @@ class EndDeviceLoraPhy : public LoraPhy
259287
*/
260288
TracedCallback<Ptr<const Packet>, uint32_t> m_wrongFrequency;
261289

290+
/**
291+
* Trace source for when a packet is lost because it was transmitted on the
292+
* same frequency different from the one this EndDeviceLoraPhy was configured to
293+
* listen on.
294+
*/
295+
TracedCallback<Ptr<const Packet>, uint32_t> m_wrongBandwidth;
296+
262297
TracedValue<State> m_state; //!< The state this PHY is currently in.
263298

264299
// static const double sensitivity[6]; //!< The sensitivity vector of this device to different
265300
// SFs
266301

267302
uint32_t m_frequencyHz; //!< The frequency [Hz] this device is listening on
268303

304+
uint32_t m_bandwidthHz; //!< The channel bandwidth [Hz] this device is listening on
305+
269306
uint8_t m_sf; //!< The Spreading Factor this device is listening for
270307

271308
/**

model/gateway-lora-phy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class GatewayLoraPhy : public LoraPhy
5555
double rxPowerDbm,
5656
uint8_t sf,
5757
Time duration,
58-
uint32_t frequencyHz) override = 0;
58+
uint32_t frequencyHz,
59+
uint32_t bandwidthHz) override = 0;
5960

6061
void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override = 0;
6162

model/lora-channel.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ LoraChannel::Send(Ptr<LoraPhy> sender,
160160
parameters.sf = txParams.sf;
161161
parameters.duration = duration;
162162
parameters.frequencyHz = frequencyHz;
163+
parameters.bandwidthHz = txParams.bandwidthHz;
163164

164165
// Schedule the receive event
165166
NS_LOG_INFO("Scheduling reception of the packet");
@@ -187,7 +188,8 @@ LoraChannel::Receive(uint32_t i, Ptr<Packet> packet, LoraChannelParameters param
187188
parameters.rxPowerDbm,
188189
parameters.sf,
189190
parameters.duration,
190-
parameters.frequencyHz);
191+
parameters.frequencyHz,
192+
parameters.bandwidthHz);
191193
}
192194

193195
double

model/lora-channel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct LoraChannelParameters
4949
uint8_t sf; //!< The Spreading Factor of this transmission.
5050
Time duration; //!< The duration of the transmission.
5151
uint32_t frequencyHz; //!< The frequency [Hz] of this transmission.
52+
uint32_t bandwidthHz; //!< The bandwidth [Hz] of this transmission.
5253
};
5354

5455
/**

model/lora-phy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ class LoraPhy : public Object
108108
* @param sf The Spreading Factor of the arriving packet.
109109
* @param duration The on air time of this packet.
110110
* @param frequencyHz The frequency this packet is being transmitted on.
111+
* @param bandwidthHz The bandwidth this packet is being transmitted on.
111112
*/
112113
virtual void StartReceive(Ptr<Packet> packet,
113114
double rxPowerDbm,
114115
uint8_t sf,
115116
Time duration,
116-
uint32_t frequencyHz) = 0;
117+
uint32_t frequencyHz,
118+
uint32_t bandwidthHz) = 0;
117119

118120
/**
119121
* Finish reception of a packet.

model/simple-end-device-lora-phy.cc

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr<Packet> packet,
9797
double rxPowerDbm,
9898
uint8_t sf,
9999
Time duration,
100-
uint32_t frequencyHz)
100+
uint32_t frequencyHz,
101+
uint32_t bandwidthHz)
101102
{
102103
NS_LOG_FUNCTION(this << packet << rxPowerDbm << unsigned(sf) << duration << frequencyHz);
103104

@@ -145,6 +146,8 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr<Packet> packet,
145146
// Save needed sensitivity
146147
double sensitivity = EndDeviceLoraPhy::sensitivity[unsigned(sf) - 7];
147148

149+
uint32_t node_id = m_device ? m_device->GetNode()->GetId() : 0;
150+
148151
// Check frequency
149152
//////////////////
150153
if (!IsOnFrequency(frequencyHz))
@@ -153,15 +156,18 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr<Packet> packet,
153156
<< frequencyHz << " Hz and we are listening at " << m_frequencyHz << " Hz");
154157

155158
// Fire the trace source for this event.
156-
if (m_device)
157-
{
158-
m_wrongFrequency(packet, m_device->GetNode()->GetId());
159-
}
160-
else
161-
{
162-
m_wrongFrequency(packet, 0);
163-
}
159+
m_wrongFrequency(packet, node_id);
160+
canLockOnPacket = false;
161+
}
162+
163+
// Check bandwidth
164+
//////////////////
165+
if (!IsOnBandwidth(bandwidthHz)) {
166+
NS_LOG_INFO("Packet lost because it's send using bandwidth "
167+
<< bandwidthHz << " Hz and we are listening at " << m_bandwidthHz << " Hz");
164168

169+
// Fire the trace source for this event.
170+
m_wrongBandwidth(packet, node_id);
165171
canLockOnPacket = false;
166172
}
167173

@@ -173,15 +179,7 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr<Packet> packet,
173179
<< unsigned(sf) << ", while we are listening for SF" << unsigned(m_sf));
174180

175181
// Fire the trace source for this event.
176-
if (m_device)
177-
{
178-
m_wrongSf(packet, m_device->GetNode()->GetId());
179-
}
180-
else
181-
{
182-
m_wrongSf(packet, 0);
183-
}
184-
182+
m_wrongSf(packet, node_id);
185183
canLockOnPacket = false;
186184
}
187185

@@ -194,15 +192,7 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr<Packet> packet,
194192
<< " dBm");
195193

196194
// Fire the trace source for this event.
197-
if (m_device)
198-
{
199-
m_underSensitivity(packet, m_device->GetNode()->GetId());
200-
}
201-
else
202-
{
203-
m_underSensitivity(packet, 0);
204-
}
205-
195+
m_underSensitivity(packet, node_id);
206196
canLockOnPacket = false;
207197
}
208198

model/simple-end-device-lora-phy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class SimpleEndDeviceLoraPhy : public EndDeviceLoraPhy
4848
double rxPowerDbm,
4949
uint8_t sf,
5050
Time duration,
51-
uint32_t frequencyHz) override;
51+
uint32_t frequencyHz,
52+
uint32_t bandwidthHz) override;
5253

5354
// Implementation of LoraPhy's pure virtual functions
5455
void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override;

model/simple-gateway-lora-phy.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ SimpleGatewayLoraPhy::StartReceive(Ptr<Packet> packet,
112112
double rxPowerDbm,
113113
uint8_t sf,
114114
Time duration,
115-
uint32_t frequencyHz)
115+
uint32_t frequencyHz,
116+
uint32_t bandwidthHz)
116117
{
117118
NS_LOG_FUNCTION(this << packet << rxPowerDbm << duration << frequencyHz);
118119

model/simple-gateway-lora-phy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class SimpleGatewayLoraPhy : public GatewayLoraPhy
4848
double rxPowerDbm,
4949
uint8_t sf,
5050
Time duration,
51-
uint32_t frequencyHz) override;
51+
uint32_t frequencyHz,
52+
uint32_t bandwidthHz) override;
5253

5354
void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override;
5455

0 commit comments

Comments
 (0)