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 * SPDX-License-Identifier: GPL-2.0-only
6 */
7
9
10#include "spectrum-wifi-phy.h"
11#include "wifi-psdu.h"
14
15#include <ns3/boolean.h>
16#include <ns3/spectrum-transmit-filter.h>
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("WifiBandwidthFilter");
22
23NS_OBJECT_ENSURE_REGISTERED(WifiBandwidthFilter);
24
29
32{
33 static TypeId tid = TypeId("ns3::WifiBandwidthFilter")
35 .SetGroupName("Wifi")
36 .AddConstructor<WifiBandwidthFilter>();
37 return tid;
38}
39
40bool
42 Ptr<const SpectrumPhy> receiverPhy)
43{
44 NS_LOG_FUNCTION(this << params);
45
46 auto wifiRxParams = DynamicCast<const WifiSpectrumSignalParameters>(params);
47 if (!wifiRxParams)
48 {
49 NS_LOG_DEBUG("Received a non Wi-Fi signal: do not filter");
50 return false;
51 }
52
53 auto interface = DynamicCast<const WifiSpectrumPhyInterface>(receiverPhy);
54 if (!interface)
55 {
56 NS_LOG_DEBUG("Sending a Wi-Fi signal to a non Wi-Fi device; do not filter");
57 return false;
58 }
59
60 auto wifiPhy = interface->GetSpectrumWifiPhy();
61 NS_ASSERT_MSG(wifiPhy,
62 "WifiPhy should be valid if WifiSpectrumSignalParameters was found and sending "
63 "to a WifiSpectrumPhyInterface");
64
65 BooleanValue trackSignalsInactiveInterfaces;
66 wifiPhy->GetAttribute("TrackSignalsFromInactiveInterfaces", trackSignalsInactiveInterfaces);
67
68 NS_ASSERT_MSG(trackSignalsInactiveInterfaces.Get() ||
69 (interface == wifiPhy->GetCurrentInterface()),
70 "DoFilter should not be called for an inactive interface if "
71 "SpectrumWifiPhy::TrackSignalsFromInactiveInterfaces attribute is not enabled");
72
73 NS_ASSERT((interface != wifiPhy->GetCurrentInterface()) ||
74 (wifiPhy->GetOperatingChannel().GetTotalWidth() == interface->GetChannelWidth()));
76 (interface != wifiPhy->GetCurrentInterface()) ||
77 (wifiPhy->GetOperatingChannel().GetFrequencies() == interface->GetCenterFrequencies()));
78
79 // The signal power is spread over a frequency interval that includes a guard
80 // band on the left and a guard band on the right of the nominal TX band
81 const auto rxCenterFreqs = wifiRxParams->ppdu->GetTxCenterFreqs();
82 // all segments have the same width
83 const auto rxWidth =
84 (wifiRxParams->ppdu->GetTxVector().GetChannelWidth() / rxCenterFreqs.size());
85 const auto guardBandwidth = wifiPhy->GetGuardBandwidth(rxWidth);
86 bool filter = true;
87 for (auto rxCenterFreq : rxCenterFreqs)
88 {
89 const auto rxMinFreq = rxCenterFreq - rxWidth / 2 - guardBandwidth;
90 const auto rxMaxFreq = rxCenterFreq + rxWidth / 2 + guardBandwidth;
91 const auto operatingFrequencies = interface->GetCenterFrequencies();
92 const auto operatingChannelWidth =
93 interface->GetChannelWidth() / operatingFrequencies.size();
94 for (auto operatingFrequency : operatingFrequencies)
95 {
96 const auto channelMinFreq = operatingFrequency - operatingChannelWidth / 2;
97 const auto channelMaxFreq = operatingFrequency + operatingChannelWidth / 2;
98 /**
99 * The PPDU can be ignored if the two bands do not overlap.
100 *
101 * First non-overlapping case:
102 *
103 * ┌─────────┬─────────┬─────────┐
104 * PPDU │ Guard │ Nominal │ Guard │
105 * │ Band │ Band │ Band │
106 * └─────────┴─────────┴─────────┘
107 * rxMinFreq rxMaxFreq
108 *
109 * channelMinFreq channelMaxFreq
110 * ┌──────────────────────────────┐
111 * │ Operating │
112 * │ Channel │
113 * └──────────────────────────────┘
114 *
115 * Second non-overlapping case:
116 *
117 * ┌─────────┬─────────┬─────────┐
118 * PPDU │ Guard │ Nominal │ Guard │
119 * │ Band │ Band │ Band │
120 * └─────────┴─────────┴─────────┘
121 * rxMinFreq rxMaxFreq
122 *
123 * channelMinFreq channelMaxFreq
124 * ┌──────────────────────────────┐
125 * │ Operating │
126 * │ Channel │
127 * └──────────────────────────────┘
128 */
129 filter &= ((rxMinFreq >= channelMaxFreq) || (rxMaxFreq <= channelMinFreq));
130 }
131 }
132 NS_LOG_DEBUG("Returning " << filter);
133 return filter;
134}
135
136int64_t
138{
139 return 0;
140}
141
142} // namespace ns3
bool Get() const
Definition boolean.cc:44
Smart pointer class similar to boost::intrusive_ptr.
spectrum-aware transmit filter object
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:55
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
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:580