A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
19 #include "wifi-bandwidth-filter.h"
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 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("WifiBandwidthFilter");
33 
34 NS_OBJECT_ENSURE_REGISTERED(WifiBandwidthFilter);
35 
37 {
38  NS_LOG_FUNCTION(this);
39 }
40 
41 TypeId
43 {
44  static TypeId tid = TypeId("ns3::WifiBandwidthFilter")
46  .SetGroupName("Wifi")
47  .AddConstructor<WifiBandwidthFilter>();
48  return tid;
49 }
50 
51 bool
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 
135  auto filter = (rxMinFreq >= channelMaxFreq || rxMaxFreq <= channelMinFreq);
136  NS_LOG_DEBUG("Returning " << filter);
137  return filter;
138 }
139 
140 int64_t
142 {
143  return 0;
144 }
145 
146 } // namespace ns3
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:931
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:586
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.