A Discrete-Event Network Simulator
API
wave-frame-exchange-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/abort.h"
23 #include "ns3/wifi-protection.h"
24 #include "ns3/wifi-acknowledgment.h"
26 #include "higher-tx-tag.h"
27 
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("WaveFrameExchangeManager");
32 
33 NS_OBJECT_ENSURE_REGISTERED (WaveFrameExchangeManager);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::WaveFrameExchangeManager")
40  .AddConstructor<WaveFrameExchangeManager> ()
41  .SetGroupName ("Wave")
42  ;
43  return tid;
44 }
45 
47 {
48  NS_LOG_FUNCTION (this);
49 }
50 
52 {
54 }
55 
56 void
58 {
59  m_scheduler = device->GetChannelScheduler ();
61  NS_ASSERT (m_scheduler != 0 && m_coordinator != 0);
62 }
63 
66 {
67  NS_LOG_FUNCTION (this << *item);
68  HigherLayerTxVectorTag datatag;
69  bool found;
70  found = ConstCast<Packet> (item->GetPacket ())->PeekPacketTag (datatag);
71  // if high layer has not controlled transmit parameters, the real transmit parameters
72  // will be determined by MAC layer itself.
73  if (!found)
74  {
75  return m_mac->GetWifiRemoteStationManager ()->GetDataTxVector (item->GetHeader ());
76  }
77 
78  // if high layer has set the transmit parameters with non-adaption mode,
79  // the real transmit parameters are determined by high layer.
80  if (!datatag.IsAdaptable ())
81  {
82  return datatag.GetTxVector ();
83  }
84 
85  // if high layer has set the transmit parameters with non-adaption mode,
86  // the real transmit parameters are determined by both high layer and MAC layer.
87  WifiTxVector txHigher = datatag.GetTxVector ();
88  WifiTxVector txMac = m_mac->GetWifiRemoteStationManager ()->GetDataTxVector (item->GetHeader ());
89  WifiTxVector txAdapter;
90  txAdapter.SetChannelWidth (10);
91  // the DataRate set by higher layer is the minimum data rate
92  // which is the lower bound for the actual data rate.
93  if (txHigher.GetMode ().GetDataRate (txHigher.GetChannelWidth ()) > txMac.GetMode ().GetDataRate (txMac.GetChannelWidth ()))
94  {
95  txAdapter.SetMode (txHigher.GetMode ());
96  txAdapter.SetPreambleType (txHigher.GetPreambleType ());
97  }
98  else
99  {
100  txAdapter.SetMode (txMac.GetMode ());
101  txAdapter.SetPreambleType (txMac.GetPreambleType ());
102  }
103  // the TxPwr_Level set by higher layer is the maximum transmit
104  // power which is the upper bound for the actual transmit power;
105  txAdapter.SetTxPowerLevel (std::min (txHigher.GetTxPowerLevel (), txMac.GetTxPowerLevel ()));
106 
107  return txAdapter;
108 }
109 
110 bool
112 {
113  NS_LOG_FUNCTION (this << dcf);
114 
115  uint32_t curChannel = m_phy->GetChannelNumber ();
116  // if current channel access is not AlternatingAccess, just do as FrameExchangeManager.
117  if (m_scheduler == 0 || !m_scheduler->IsAlternatingAccessAssigned (curChannel))
118  {
120  }
121 
122  m_txTimer.Cancel ();
123  m_dcf = dcf;
124 
125  Ptr<WifiMacQueue> queue = dcf->GetWifiMacQueue ();
126 
127  if (queue->IsEmpty ())
128  {
129  NS_LOG_DEBUG ("Queue empty");
131  m_dcf = 0;
132  return false;
133  }
134 
136  Ptr<WifiMacQueueItem> mpdu = *queue->Peek ()->GetQueueIteratorPairs ().front ().it;
137  NS_ASSERT (mpdu != 0);
138 
139  // assign a sequence number if this is not a fragment nor a retransmission
140  if (!mpdu->IsFragment () && !mpdu->GetHeader ().IsRetry ())
141  {
142  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor (&mpdu->GetHeader ());
143  mpdu->GetHeader ().SetSequenceNumber (sequence);
144  }
145 
146  WifiTxParameters txParams;
147  txParams.m_txVector = GetDataTxVector (mpdu);
148  Time remainingTime = m_coordinator->NeedTimeToGuardInterval ();
149 
150  if (!TryAddMpdu (mpdu, txParams, remainingTime))
151  {
152  // The attempt for this transmission will be canceled;
153  // and this packet will be pending for next transmission by QosTxop class
154  NS_LOG_DEBUG ("Because the required transmission time exceeds the remainingTime = "
155  << remainingTime.As (Time::MS)
156  << ", currently this packet will not be transmitted.");
157  }
158  else
159  {
160  SendMpduWithProtection (mpdu, txParams);
161  return true;
162  }
163  return false;
164 }
165 
166 void
168 {
169  NS_LOG_FUNCTION (this);
170  m_scheduler = 0;
171  m_coordinator = 0;
173 }
174 
175 } //namespace ns3
bool IsRetry(void) const
Return if the Retry bit is set.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
static TypeId GetTypeId(void)
Get the type ID.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool IsAdaptable(void) const
WifiTxTimer m_txTimer
the timer set upon frame transmission
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SendMpduWithProtection(Ptr< WifiMacQueueItem > mpdu, WifiTxParameters &txParams)
Send an MPDU with the given TX parameters (with the specified protection).
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
Ptr< WifiPhy > m_phy
the PHY layer on this station
#define min(a, b)
Definition: 80211b.c:42
#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
Time NeedTimeToGuardInterval(Time duration=Seconds(0.0)) const
Ptr< ChannelScheduler > GetChannelScheduler(void) const
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ptr< RegularWifiMac > m_mac
the MAC layer on this station
This tag will be used to support higher layer control DataRate and TxPwr_Level for transmission...
Definition: higher-tx-tag.h:47
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(void) const
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
virtual void DoDispose(void)
Destructor implementation.
QosFrameExchangeManager handles the frame exchange sequences for QoS stations.
WifiTxVector GetTxVector(void) const
virtual WifiTxVector GetDataTxVector(Ptr< const WifiMacQueueItem > item) const
Return a TXVECTOR for the DATA frame given the destination.
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
Definition: txop.cc:349
virtual bool StartTransmission(Ptr< Txop > dcf)
Request the FrameExchangeManager to start a frame exchange sequence.
Ptr< ChannelScheduler > m_scheduler
the channel scheduler
Ptr< ChannelCoordinator > GetChannelCoordinator(void) const
bool IsFragment(void) const
Return true if this item contains an MSDU fragment, false otherwise.
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
void DoDispose() override
Destructor implementation.
void Cancel(void)
Cancel the timer.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1199
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
virtual void NotifyChannelAccessed(Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
Definition: txop.cc:342
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
virtual bool StartTransmission(Ptr< Txop > dcf)
Request the FrameExchangeManager to start a frame exchange sequence.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:150
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism...
Ptr< Txop > m_dcf
the DCF/EDCAF that gained channel access
uint8_t GetTxPowerLevel(void) const
uint16_t GetChannelWidth(void) const
Ptr< ChannelCoordinator > m_coordinator
the channel coordinator
void SetWaveNetDevice(Ptr< WaveNetDevice > device)
bool TryAddMpdu(Ptr< const WifiMacQueueItem > mpdu, WifiTxParameters &txParams, Time availableTime) const
Recompute the protection and acknowledgment methods to use if the given MPDU is added to the frame be...
millisecond
Definition: nstime.h:116
Ptr< MacTxMiddle > m_txMiddle
the MAC TX Middle on this station
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100