A Discrete-Event Network Simulator
API
constant-obss-pd-algorithm.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 University of Washington
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  * Author: S├ębastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/node.h"
23 #include "ns3/config.h"
24 #include "ns3/double.h"
26 #include "ns3/sta-wifi-mac.h"
27 #include "ns3/wifi-utils.h"
28 #include "ns3/wifi-phy.h"
29 #include "he-phy.h"
30 #include "ns3/wifi-net-device.h"
31 #include "he-configuration.h"
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("ConstantObssPdAlgorithm");
36 NS_OBJECT_ENSURE_REGISTERED (ConstantObssPdAlgorithm);
37 
39  : ObssPdAlgorithm ()
40 {
41  NS_LOG_FUNCTION (this);
42 }
43 
44 TypeId
46 {
47  static ns3::TypeId tid = ns3::TypeId ("ns3::ConstantObssPdAlgorithm")
49  .SetGroupName ("Wifi")
50  .AddConstructor<ConstantObssPdAlgorithm> ()
51  ;
52  return tid;
53 }
54 
55 void
57 {
58  Ptr<WifiPhy> phy = device->GetPhy ();
59  auto hePhy = DynamicCast<HePhy> (phy->GetPhyEntity (WIFI_MOD_CLASS_HE));
60  NS_ASSERT (hePhy);
61  hePhy->SetEndOfHeSigACallback (MakeCallback (&ConstantObssPdAlgorithm::ReceiveHeSigA, this));
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this << +params.bssColor << WToDbm (params.rssiW));
69 
70  Ptr<StaWifiMac> mac = m_device->GetMac ()->GetObject<StaWifiMac>();
71  if (mac && !mac->IsAssociated ())
72  {
73  NS_LOG_DEBUG ("This is not an associated STA: skip OBSS PD algorithm");
74  return;
75  }
76 
77  Ptr<HeConfiguration> heConfiguration = m_device->GetHeConfiguration ();
78  NS_ASSERT (heConfiguration);
79  uint8_t bssColor = heConfiguration->GetBssColor ();
80 
81  if (bssColor == 0)
82  {
83  NS_LOG_DEBUG ("BSS color is 0");
84  return;
85  }
86  if (params.bssColor == 0)
87  {
88  NS_LOG_DEBUG ("Received BSS color is 0");
89  return;
90  }
91  //TODO: SRP_AND_NON-SRG_OBSS-PD_PROHIBITED=1 => OBSS_PD SR is not allowed
92 
93  bool isObss = (bssColor != params.bssColor);
94  if (isObss)
95  {
96  if (WToDbm (params.rssiW) < m_obssPdLevel)
97  {
98  NS_LOG_DEBUG ("Frame is OBSS and RSSI " << WToDbm(params.rssiW) << " is below OBSS-PD level of " << m_obssPdLevel << "; reset PHY to IDLE");
99  ResetPhy (params);
100  }
101  else
102  {
103  NS_LOG_DEBUG ("Frame is OBSS and RSSI is above OBSS-PD level");
104  }
105  }
106 }
107 
108 } //namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Parameters for received HE-SIG-A for OBSS_PD based SR.
Definition: he-phy.h:46
Ptr< HeConfiguration > GetHeConfiguration(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static TypeId GetTypeId(void)
Get the type ID.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
OBSS PD algorithm interfaceThis object provides the interface for all OBSS_PD algorithms and is desig...
uint8_t bssColor
BSS color.
Definition: he-phy.h:49
phy
Definition: third.py:93
double m_obssPdLevel
Current OBSS PD level (dBm)
virtual void ConnectWifiNetDevice(const Ptr< WifiNetDevice > device)
Connect the WifiNetDevice and setup eventual callbacks.
mac
Definition: third.py:99
Ptr< WifiPhy > GetPhy(void) const
Ptr< WifiNetDevice > m_device
Pointer to the WifiNetDevice.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void ReceiveHeSigA(HeSigAParameters params)
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:47
double rssiW
RSSI in W.
Definition: he-phy.h:48
Ptr< WifiMac > GetMac(void) const
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Constant OBSS PD algorithmThis constant OBSS_PD algorithm is a simple OBSS_PD algorithm which evaluat...
Declaration of ns3::HePhy class and ns3::HeSigAParameters struct.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
void ConnectWifiNetDevice(const Ptr< WifiNetDevice > device)
Connect the WifiNetDevice and setup eventual callbacks.
The Wifi MAC high model for a non-AP STA in a BSS.
Definition: sta-wifi-mac.h:106
void ResetPhy(HeSigAParameters params)
Reset PHY to IDLE.