A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-bandwidth-filter.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Universita' degli Studi di Napoli "Federico II"
3 * Copyright (c) 2022 University of Washington (port logic to WifiBandwidthFilter)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
20
21#include "spectrum-wifi-phy.h"
22#include "wifi-psdu.h"
25
26#include <ns3/boolean.h>
27#include <ns3/spectrum-transmit-filter.h>
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("WifiBandwidthFilter");
33
34NS_OBJECT_ENSURE_REGISTERED(WifiBandwidthFilter);
35
37{
38 NS_LOG_FUNCTION(this);
39}
40
43{
44 static TypeId tid = TypeId("ns3::WifiBandwidthFilter")
46 .SetGroupName("Wifi")
47 .AddConstructor<WifiBandwidthFilter>();
48 return tid;
49}
50
51bool
53 Ptr<const SpectrumPhy> receiverPhy)
54{
55 NS_LOG_FUNCTION(this << params);
56
57 auto wifiRxParams = DynamicCast<const WifiSpectrumSignalParameters>(params);
58 if (!wifiRxParams)
59 {
60 NS_LOG_DEBUG("Received a non Wi-Fi signal: do not filter");
61 return false;
62 }
63
64 auto interface = DynamicCast<const WifiSpectrumPhyInterface>(receiverPhy);
65 if (!interface)
66 {
67 NS_LOG_DEBUG("Sending a Wi-Fi signal to a non Wi-Fi device; do not filter");
68 return false;
69 }
70
71 auto wifiPhy = interface->GetSpectrumWifiPhy();
72 NS_ASSERT_MSG(wifiPhy,
73 "WifiPhy should be valid if WifiSpectrumSignalParameters was found and sending "
74 "to a WifiSpectrumPhyInterface");
75
76 BooleanValue trackSignalsInactiveInterfaces;
77 wifiPhy->GetAttribute("TrackSignalsFromInactiveInterfaces", trackSignalsInactiveInterfaces);
78
79 NS_ASSERT_MSG(trackSignalsInactiveInterfaces.Get() ||
80 (interface == wifiPhy->GetCurrentInterface()),
81 "DoFilter should not be called for an inactive interface if "
82 "SpectrumWifiPhy::TrackSignalsFromInactiveInterfaces attribute is not enabled");
83
84 NS_ASSERT((interface != wifiPhy->GetCurrentInterface()) ||
85 (wifiPhy->GetOperatingChannel().GetFrequency() == interface->GetCenterFrequency()));
86 NS_ASSERT((interface != wifiPhy->GetCurrentInterface()) ||
87 (wifiPhy->GetOperatingChannel().GetWidth() == interface->GetChannelWidth()));
88
89 // The signal power is spread over a frequency interval that includes a guard
90 // band on the left and a guard band on the right of the nominal TX band
91
92 const auto rxCenterFreq = wifiRxParams->ppdu->GetTxCenterFreq();
93 const auto rxWidth = wifiRxParams->ppdu->GetTxVector().GetChannelWidth();
94 const auto guardBandwidth = wifiPhy->GetGuardBandwidth(rxWidth);
95 const auto operatingFrequency = interface->GetCenterFrequency();
96 const auto operatingChannelWidth = interface->GetChannelWidth();
97
98 const auto rxMinFreq = rxCenterFreq - rxWidth / 2 - guardBandwidth;
99 const auto rxMaxFreq = rxCenterFreq + rxWidth / 2 + guardBandwidth;
100
101 const auto channelMinFreq = operatingFrequency - operatingChannelWidth / 2;
102 const auto channelMaxFreq = operatingFrequency + operatingChannelWidth / 2;
103
104 /**
105 * The PPDU can be ignored if the two bands do not overlap.
106 *
107 * First non-overlapping case:
108 *
109 * ┌─────────┬─────────┬─────────┐
110 * PPDU │ Guard │ Nominal │ Guard │
111 * │ Band │ Band │ Band │
112 * └─────────┴─────────┴─────────┘
113 * rxMinFreq rxMaxFreq
114 *
115 * channelMinFreq channelMaxFreq
116 * ┌──────────────────────────────┐
117 * │ Operating │
118 * │ Channel │
119 * └──────────────────────────────┘
120 *
121 * Second non-overlapping case:
122 *
123 * ┌─────────┬─────────┬─────────┐
124 * PPDU │ Guard │ Nominal │ Guard │
125 * │ Band │ Band │ Band │
126 * └─────────┴─────────┴─────────┘
127 * rxMinFreq rxMaxFreq
128 *
129 * channelMinFreq channelMaxFreq
130 * ┌──────────────────────────────┐
131 * │ Operating │
132 * │ Channel │
133 * └──────────────────────────────┘
134 */
135 auto filter = (rxMinFreq >= channelMaxFreq || rxMaxFreq <= channelMinFreq);
136 NS_LOG_DEBUG("Returning " << filter);
137 return filter;
138}
139
140int64_t
142{
143 return 0;
144}
145
146} // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
bool Get() const
Definition: boolean.cc:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
spectrum-aware transmit filter object
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Introspection did not find any typical Config paths.
static TypeId GetTypeId()
Get the type ID.
int64_t DoAssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
bool DoFilter(Ptr< const SpectrumSignalParameters > params, Ptr< const SpectrumPhy > receiverPhy) override
Ignore the signal being received if it is a Wi-Fi PPDU whose TX band (including guard bands) does not...
This class is an adaptor between class SpectrumWifiPhy (which inherits from WifiPhy) and class Spectr...
#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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition: ptr.h:591