A Discrete-Event Network Simulator
API
wave-frame-exchange-manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 "higher-tx-tag.h"
23 
24 #include "ns3/abort.h"
25 #include "ns3/log.h"
26 #include "ns3/qos-blocked-destinations.h"
27 #include "ns3/wifi-acknowledgment.h"
28 #include "ns3/wifi-protection.h"
29 
30 namespace ns3
31 {
32 
33 NS_LOG_COMPONENT_DEFINE("WaveFrameExchangeManager");
34 
35 NS_OBJECT_ENSURE_REGISTERED(WaveFrameExchangeManager);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId("ns3::WaveFrameExchangeManager")
42  .AddConstructor<WaveFrameExchangeManager>()
43  .SetGroupName("Wave");
44  return tid;
45 }
46 
48 {
49  NS_LOG_FUNCTION(this);
50 }
51 
53 {
55 }
56 
57 void
59 {
60  m_scheduler = device->GetChannelScheduler();
63 }
64 
67 {
68  NS_LOG_FUNCTION(this << *item);
69  HigherLayerTxVectorTag datatag;
70  bool found;
71  found = ConstCast<Packet>(item->GetPacket())->PeekPacketTag(datatag);
72  // if high layer has not controlled transmit parameters, the real transmit parameters
73  // will be determined by MAC layer itself.
74  if (!found)
75  {
76  return m_mac->GetWifiRemoteStationManager()->GetDataTxVector(item->GetHeader(),
78  }
79 
80  // if high layer has set the transmit parameters with non-adaption mode,
81  // the real transmit parameters are determined by high layer.
82  if (!datatag.IsAdaptable())
83  {
84  return datatag.GetTxVector();
85  }
86 
87  // if high layer has set the transmit parameters with non-adaption mode,
88  // the real transmit parameters are determined by both high layer and MAC layer.
89  WifiTxVector txHigher = datatag.GetTxVector();
90  WifiTxVector txMac =
92  WifiTxVector txAdapter;
93  txAdapter.SetChannelWidth(10);
94  // the DataRate set by higher layer is the minimum data rate
95  // which is the lower bound for the actual data rate.
96  if (txHigher.GetMode().GetDataRate(txHigher.GetChannelWidth()) >
97  txMac.GetMode().GetDataRate(txMac.GetChannelWidth()))
98  {
99  txAdapter.SetMode(txHigher.GetMode());
100  txAdapter.SetPreambleType(txHigher.GetPreambleType());
101  }
102  else
103  {
104  txAdapter.SetMode(txMac.GetMode());
105  txAdapter.SetPreambleType(txMac.GetPreambleType());
106  }
107  // the TxPwr_Level set by higher layer is the maximum transmit
108  // power which is the upper bound for the actual transmit power;
109  txAdapter.SetTxPowerLevel(std::min(txHigher.GetTxPowerLevel(), txMac.GetTxPowerLevel()));
110 
111  return txAdapter;
112 }
113 
114 bool
116 {
117  NS_LOG_FUNCTION(this << dcf << allowedWidth);
118 
119  uint32_t curChannel = m_phy->GetChannelNumber();
120  // if current channel access is not AlternatingAccess, just do as FrameExchangeManager.
121  if (!m_scheduler || !m_scheduler->IsAlternatingAccessAssigned(curChannel))
122  {
123  return FrameExchangeManager::StartTransmission(dcf, allowedWidth);
124  }
125 
126  m_txTimer.Cancel();
127  m_dcf = dcf;
128  m_allowedWidth = allowedWidth;
129 
130  Ptr<WifiMacQueue> queue = dcf->GetWifiMacQueue();
131 
132  if (queue->IsEmpty())
133  {
134  NS_LOG_DEBUG("Queue empty");
136  m_dcf = nullptr;
137  return false;
138  }
139 
141  Ptr<WifiMpdu> mpdu = queue->PeekFirstAvailable(0);
142  NS_ASSERT(mpdu);
143 
144  // assign a sequence number if this is not a fragment nor a retransmission
145  if (!mpdu->IsFragment() && !mpdu->GetHeader().IsRetry())
146  {
147  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor(&mpdu->GetHeader());
148  mpdu->GetHeader().SetSequenceNumber(sequence);
149  }
150 
151  WifiTxParameters txParams;
152  txParams.m_txVector = GetDataTxVector(mpdu);
153  Time remainingTime = m_coordinator->NeedTimeToGuardInterval();
154 
155  if (!TryAddMpdu(mpdu, txParams, remainingTime))
156  {
157  // The attempt for this transmission will be canceled;
158  // and this packet will be pending for next transmission by QosTxop class
159  NS_LOG_DEBUG("Because the required transmission time exceeds the remainingTime = "
160  << remainingTime.As(Time::MS)
161  << ", currently this packet will not be transmitted.");
162  }
163  else
164  {
165  SendMpduWithProtection(mpdu, txParams);
166  return true;
167  }
168  return false;
169 }
170 
171 void
173 {
174  NS_LOG_FUNCTION(this);
175  m_scheduler = nullptr;
176  m_coordinator = nullptr;
178 }
179 
180 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:42
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
Ptr< WifiMac > m_mac
the MAC layer on this station
void SendMpduWithProtection(Ptr< WifiMpdu > mpdu, WifiTxParameters &txParams)
Send an MPDU with the given TX parameters (with the specified protection).
Ptr< MacTxMiddle > m_txMiddle
the MAC TX Middle on this station
uint16_t m_allowedWidth
the allowed width in MHz for the current transmission
WifiTxTimer m_txTimer
the timer set upon frame transmission
Ptr< Txop > m_dcf
the DCF/EDCAF that gained channel access
Ptr< WifiPhy > m_phy
the PHY layer on this station
void DoDispose() override
Destructor implementation.
virtual bool StartTransmission(Ptr< Txop > dcf, uint16_t allowedWidth)
Request the FrameExchangeManager to start a frame exchange sequence.
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission.
Definition: higher-tx-tag.h:48
WifiTxVector GetTxVector() const
QosFrameExchangeManager handles the frame exchange sequences for QoS stations.
bool TryAddMpdu(Ptr< const WifiMpdu > mpdu, WifiTxParameters &txParams, Time availableTime) const
Recompute the protection and acknowledgment methods to use if the given MPDU is added to the frame be...
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
@ MS
millisecond
Definition: nstime.h:117
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:220
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: txop.cc:585
virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted on the given link f...
Definition: txop.cc:578
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
static TypeId GetTypeId()
Get the type ID.
Ptr< ChannelCoordinator > m_coordinator
the channel coordinator
bool StartTransmission(Ptr< Txop > dcf, uint16_t allowedWidth) override
Request the FrameExchangeManager to start a frame exchange sequence.
virtual WifiTxVector GetDataTxVector(Ptr< const WifiMpdu > item) const
Return a TXVECTOR for the DATA frame given the destination.
Ptr< ChannelScheduler > m_scheduler
the channel scheduler
void DoDispose() override
Destructor implementation.
Ptr< ChannelScheduler > GetChannelScheduler() const
Ptr< ChannelCoordinator > GetChannelCoordinator() const
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(uint8_t linkId=0) const
Definition: wifi-mac.cc:886
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
uint8_t GetChannelNumber() const
Return current channel number.
Definition: wifi-phy.cc:1020
WifiTxVector GetDataTxVector(const WifiMacHeader &header, uint16_t allowedWidth)
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
void Cancel()
Cancel the timer.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
WifiPreamble GetPreambleType() const
uint8_t GetTxPowerLevel() const
uint16_t GetChannelWidth() const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.