A Discrete-Event Network Simulator
API
eht-frame-exchange-manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Universita' degli Studi di Napoli Federico II
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Stefano Avallone <stavallo@unina.it>
18  */
19 
21 
22 #include "eht-phy.h"
23 
24 #include "ns3/abort.h"
25 #include "ns3/log.h"
26 
27 #undef NS_LOG_APPEND_CONTEXT
28 #define NS_LOG_APPEND_CONTEXT std::clog << "[link=" << +m_linkId << "][mac=" << m_self << "] "
29 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("EhtFrameExchangeManager");
34 
35 NS_OBJECT_ENSURE_REGISTERED(EhtFrameExchangeManager);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId("ns3::EhtFrameExchangeManager")
42  .AddConstructor<EhtFrameExchangeManager>()
43  .SetGroupName("Wifi");
44  return tid;
45 }
46 
48 {
49  NS_LOG_FUNCTION(this);
50 }
51 
53 {
55 }
56 
57 void
59 {
60  m_msduAggregator->SetLinkId(linkId);
61  m_mpduAggregator->SetLinkId(linkId);
63 }
64 
67 {
68  NS_LOG_FUNCTION(this << *mpdu);
69 
70  // alias needs only be created for non-broadcast data frames exchanged between two MLDs
71  if (!mpdu->GetHeader().IsData() || m_mac->GetNLinks() == 1 ||
72  mpdu->GetHeader().GetAddr1().IsGroup() ||
73  !GetWifiRemoteStationManager()->GetMldAddress(mpdu->GetHeader().GetAddr1()))
74  {
76  }
77 
78  mpdu = mpdu->CreateAlias(m_linkId);
79  auto& hdr = mpdu->GetHeader();
80  hdr.SetAddr2(GetAddress());
83  hdr.SetAddr1(*address);
84  /*
85  * Set Address3 according to Table 9-30 of 802.11-2020 and Section 35.3.3 of
86  * 802.11be D2.0 ["the value of the Address 3 field and the Address 4 field (if present)
87  * in the MAC header of a data frame shall be set based on Table 9-30 (Address field
88  * contents) and the settings of the To DS and From DS bits, where the BSSID is the
89  * MAC address of the AP affiliated with the AP MLD corresponding to that link"].
90  */
91  if (hdr.IsQosAmsdu())
92  {
93  if (hdr.IsToDs() && !hdr.IsFromDs())
94  {
95  // from STA to AP: BSSID is in Address1
96  hdr.SetAddr3(hdr.GetAddr1());
97  }
98  else if (!hdr.IsToDs() && hdr.IsFromDs())
99  {
100  // from AP to STA: BSSID is in Address2
101  hdr.SetAddr3(hdr.GetAddr2());
102  }
103  }
104 
105  return mpdu;
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION(this << psdu << txVector);
112 
113  // EHT-SIG, the equivalent of HE-SIG-B, is present in EHT SU transmissions, too
114  if (txVector.GetPreambleType() == WIFI_PREAMBLE_EHT_MU)
115  {
116  auto phy = StaticCast<EhtPhy>(m_phy->GetPhyEntity(WIFI_MOD_CLASS_EHT));
117  auto sigBMode = phy->GetSigBMode(txVector);
118  txVector.SetSigBMode(sigBMode);
119  }
120 
122 }
123 
124 std::optional<double>
126 {
128 
129  if (optRssi)
130  {
131  return optRssi;
132  }
133 
134  auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(address);
135 
136  if (!mldAddress)
137  {
138  // not an MLD, nothing else can be done
139  return std::nullopt;
140  }
141 
142  for (uint8_t linkId = 0; linkId < m_mac->GetNLinks(); linkId++)
143  {
144  std::optional<Mac48Address> linkAddress;
145  if (linkId != m_linkId &&
147  *mldAddress)) &&
148  (optRssi = m_mac->GetWifiRemoteStationManager(linkId)->GetMostRecentRssi(*linkAddress)))
149  {
150  return optRssi;
151  }
152  }
153 
154  return std::nullopt;
155 }
156 
157 } // namespace ns3
void ForwardPsduDown(Ptr< const WifiPsdu > psdu, WifiTxVector &txVector) override
Forward a PSDU down to the PHY layer.
Ptr< WifiMpdu > CreateAliasIfNeeded(Ptr< WifiMpdu > mpdu) const override
Create an alias of the given MPDU for transmission by this Frame Exchange Manager.
static TypeId GetTypeId()
Get the type ID.
std::optional< double > GetMostRecentRssi(const Mac48Address &address) const override
Get the RSSI (in dBm) of the most recent packet received from the station having the given address.
void SetLinkId(uint8_t linkId) override
Set the ID of the link this Frame Exchange Manager is associated with.
uint8_t m_linkId
the ID of the link this object is associated with
Ptr< WifiMac > m_mac
the MAC layer on this station
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
Mac48Address GetAddress() const
Get the MAC address.
virtual void SetLinkId(uint8_t linkId)
Set the ID of the link this Frame Exchange Manager is associated with.
Ptr< WifiPhy > m_phy
the PHY layer on this station
HeFrameExchangeManager handles the frame exchange sequences for HE stations.
virtual std::optional< double > GetMostRecentRssi(const Mac48Address &address) const
Get the RSSI (in dBm) of the most recent packet received from the station having the given address.
Ptr< MpduAggregator > m_mpduAggregator
A-MPDU aggregator.
virtual void ForwardPsduDown(Ptr< const WifiPsdu > psdu, WifiTxVector &txVector)
Forward a PSDU down to the PHY layer.
Ptr< MsduAggregator > m_msduAggregator
A-MSDU aggregator.
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
virtual Ptr< WifiMpdu > CreateAliasIfNeeded(Ptr< WifiMpdu > mpdu) const
Create an alias of the given MPDU for transmission by this Frame Exchange Manager.
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
uint8_t GetNLinks() const
Get the number of links (can be greater than 1 for 11be devices only).
Definition: wifi-mac.cc:906
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(uint8_t linkId=0) const
Definition: wifi-mac.cc:886
Ptr< PhyEntity > GetPhyEntity(WifiModulationClass modulation) const
Get the supported PHY entity corresponding to the modulation class.
Definition: wifi-phy.cc:704
std::optional< Mac48Address > GetAffiliatedStaAddress(const Mac48Address &mldAddress) const
Get the address of the remote station operating on this link and affiliated with the MLD having the g...
std::optional< double > GetMostRecentRssi(Mac48Address address) const
std::optional< Mac48Address > GetMldAddress(const Mac48Address &address) const
Get the address of the MLD the given station is affiliated with, if any.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiPreamble GetPreambleType() const
void SetSigBMode(const WifiMode &mode)
Set the MCS used for SIG-B.
Declaration of ns3::EhtPhy class.
#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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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
@ WIFI_PREAMBLE_EHT_MU
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:82