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"
25 #include "ns3/uinteger.h"
27 #include "sta-wifi-mac.h"
28 #include "wifi-utils.h"
29 #include "wifi-phy.h"
30 #include "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  phy->TraceConnectWithoutContext ("EndOfHePreamble", MakeCallback (&ConstantObssPdAlgorithm::ReceiveHeSig, this));
61 }
62 
63 void
65 {
66  NS_LOG_FUNCTION (this << +params.bssColor << WToDbm (params.rssiW));
67 
68  Ptr<StaWifiMac> mac = m_device->GetMac ()->GetObject<StaWifiMac>();
69  if (mac && !mac->IsAssociated ())
70  {
71  NS_LOG_DEBUG ("This is not an associated STA: skip OBSS PD algorithm");
72  return;
73  }
74 
75  Ptr<HeConfiguration> heConfiguration = m_device->GetHeConfiguration ();
76  NS_ASSERT (heConfiguration);
77  UintegerValue bssColorAttribute;
78  heConfiguration->GetAttribute ("BssColor", bssColorAttribute);
79  uint8_t bssColor = bssColorAttribute.Get ();
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 "...
Ptr< HeConfiguration > GetHeConfiguration(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#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:204
OBSS PD algorithm interfaceThis object provides the interface for all OBSS_PD algorithms and is desig...
phy
Definition: third.py:93
double rssiW
RSSI in W.
Definition: wifi-phy.h:80
uint8_t bssColor
BSS color.
Definition: wifi-phy.h:81
void ReceiveHeSig(HePreambleParameters params)
double m_obssPdLevel
Current OBSS PD level.
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual void ConnectWifiNetDevice(const Ptr< WifiNetDevice > device)
Connect the WifiNetDevice and setup eventual callbacks.
mac
Definition: third.py:99
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
uint64_t Get(void) const
Definition: uinteger.cc:35
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.
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:47
void ResetPhy(HePreambleParameters params)
Reset PHY to IDLE.
Ptr< WifiMac > GetMac(void) const
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
Constant OBSS PD algorithmThis constant OBSS_PD algorithm is a simple OBSS_PD algorithm which evalute...
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
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